• Hello,

    1rst, I’m a newbie, so this topic is quite simple for old members, I guess.

    My project ist to create a directory of people working together as a tools for finding informations.

    I created a custom post type for “Staff Members”. I also created two custom taxonomies for sorting them : some “Keywords” and working “Themes”.

    In an new archive template I want to display the 3 type of informations.

    Here’s a screencap of the page running under MAMP localy:
    (right click > open image in a new tab for a better vision).

    In Zone 1 & 2, I use the following code :

    <div id="staff-keywords" class="col span_1_of_2">				
    <h2 class="title-info-staff-member"><?php _e( 'Keywords:' ); ?></h2>
    <form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
    <?php wp_dropdown_categories( 'show_count=1&taxonomy=sm_keywords' ); ?>
    <input type="submit" name="submit" value="view" />
    </form>
    <br /></div>

    The problem is : when I choose a keyword or a theme the right page (with a slug as selected) is displayed. Where am I wrong. I guess it should be fairly simple.

    In zone 3, I use the following code :

    <div id="list-staff-members" class="clear directory"><!--START listing Staff Members-->
    			
    <?php // query $the_query = new WP_Query(array(
    'post_type'	=> 'staffmembers',
    'posts_per_page'=> 5,
    'meta_key'	=> 'sorting_key',
    'orderby'	=> 'meta_value',
    'order'		=> 'ASC'
    )); ?>
    									
    <?php if( $the_query->have_posts() ): ?>	
    <h2 class="title-info-staff-member">Staff Members</h2>
    
    <ul>
    <?php while( $the_query->have_posts() ) : $the_query->the_post(); $class = get_field('sorting_key') ? 'class="sorting_key"' : ''; ?>
    					
    <li <?php echo $class; ?>>
    					
    <h2 class="the-staff-member-name-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <p>
    <?php echo get_the_term_list($post->ID, 'sm_keywords', '<span class="obvious-element-staff-member">Keywords&nbsp;:&nbsp;</span>', ', ' ,'') ?> <br /> 
    <?php echo get_the_term_list($post->ID, 'primary_theme', '<span class="obvious-element-staff-member">Theme&nbsp;:&nbsp;</span>', ', ' ,'') ?>
    </p><br />
    </li>
    				
    <?php endwhile; ?>
    </ul>
    <!--page links-->
    <?php echo paginate_links (); ?>
    <?php endif; ?>
    <?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>
    <?php else : ?>
    <?php get_template_part( 'content', 'staffmember_detail' ); ?><!--list each staff member details-->
    <?php endif; ?>
    </div><!-- END Staff Members listing  -->

    In this case, when I select another page with the <?php echo paginate_links (); ?>, the URL changes accordingly but not the five Staff Members informations.
    Let’s say I click on page two and the same list of five Staff Members remains.

    Here again, I guess the solution is quite simple. I’dlike to learn more with thoses cases.

    Is anybody have a solution?
    Many THX in advance. Have a good WE.

    V.

    • This topic was modified 7 years, 5 months ago by sempervince.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The problem is paginate_links() doesn’t know anything about your custom staff query and your custom staff query doesn’t know anything about page links. paginate_links() isn’t paging staff members, it’s paging whatever the main internal query was to get your page displayed to begin with. The page links are not coordinated with the number of staff. There will likely be too many or too few pages for the number of staff there are. There are parameters you can pass to paginate_links() to force it to display the right number of pages. Refer to the doc page.

    Of course your code would need to know how many staff there really are in order to know what the last page number is. Fortunately, query objects know this, you can get the number with $the_query->max_num_pages.

    Your query also needs to know what page has been requested so it can display the appropriate staff on the requested page. You can use the “paged” query argument added to your argument array. You could extract the page number directly from $_SERVER[‘REQUEST_URI’] using PHP string functions. Or you can steal it from the main query’s “paged” value. You can get the main query object through the global $wp_query. Once you declare that as global, the paged value can be retrieved with $wp_query->get('paged'); This property is not always defined, so if no value is returned, you should set your “paged” value to 1.

    Thread Starter sempervince

    (@sempervince)

    Hey, thx for this answer. It lighten the path. I’ll see how I can manage this.

    • This reply was modified 7 years, 5 months ago by sempervince.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Navigation tag and dropdowns in an archive template’ is closed to new replies.