• Resolved Chris

    (@nutlog13)


    Hello, I have a custom post type that I’m listing on a page. Everything shows up fine; it’s showing the right number of posts, only the pagination won’t show up. What am I missing here? Seems like something small and simple I’m just not seeing:

    <?php
    $postId = get_the_ID();
    $args = array('post_type'  => 'news',
    'post_status'          => 'publish',
    'order'                => 'desc',
    'posts_per_page' => '10'
    );
    
    $loop = new WP_Query($args);
    
    while ( $loop->have_posts() ) : $loop->the_post();
    	$newsId = $loop->post->ID;
    	$newsLink = get_permalink($newsId);
    	$newsExcerpt = get_excerpt($newsId);
    	$content = get_the_content();
    	$smallContent = substr($content, 0, 300);
    	if($newsExcerpt =="") $newsExcerpt = $smallContent;
    		  ?>
    
    	    <div class="row-fluid post-grid">
    	      <p class="post-date"><?php the_date('l, F j, Y');?></p>
    	        <h3><a href="<?php echo $newsLink;?>"><?php the_title();?></a></h3>
    	          <p><?php echo $newsExcerpt;?></p>
    	        </div>
    	        <?php endwhile;?>
    
    			<?php if(function_exists('wp_simple_pagination')) {
    		    wp_simple_pagination();
    			} ?>

    Thank you in advance for any help at all!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi

    Kindly change this part

    $args = array('post_type'  => 'news',
    'post_status'          => 'publish',
    'order'                => 'desc',
    'posts_per_page' => '10'
    );
    
    $loop = new WP_Query($args);

    to

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array('post_type'  => 'news',
    'post_status'          => 'publish',
    'order'                => 'desc',
    'posts_per_page' => '10',
    'paged'=>$paged
    );
    
    $loop = new WP_Query($args);

    Regards,
    PD

    Thread Starter Chris

    (@nutlog13)

    Hi PD, thank you for the reply! Unfortunately that code is still not working for me for some reason.

    Does it matter that this is on a PAGE template (i.e. not index), or am I missing anything else? I’ve tried changing ‘paged’ to ‘page’ in your code but still no luck…

    It seems so simple but the pagination just won’t show up. Thanks!

    what plugin or code is used for wp_simple_pagination(); ?
    does that pagination code work on custom post types?

    would the pagination link show if you try to use the generic WordPress functions next_posts_link() and previous_posts_link() ?

    example:

    next_posts_link( 'Older Entries', $loop->max_num_pages );
    previous_posts_link( 'Newer Entries', $loop->max_num_pages );

    http://codex.wordpress.org/Function_Reference/next_posts_link

    Thread Starter Chris

    (@nutlog13)

    Thanks for the reply. The standard WP functions you posted give me an “Older Entries” link, which goes to the page /latest-news/page/2. However, that page 2 displays the same first 10 posts and won’t actually show any previous posts or pages.

    The plugin I’m using is Simple Pagination (https://wordpress.org/plugins/simple-pagination). That gives me a “Pages” title at the bottom of the page, as in the function appears to be working, but no actual links to previous posts/pages. But I can’t figure out why the default WP functions won’t work either. :/

    The standard WP functions you posted give me an “Older Entries” link, which goes to the page /latest-news/page/2. However, that page 2 displays the same first 10 posts and won’t actually show any previous posts or pages.

    you need to try to apply the fix suggested by @the Grey Parrots, i.e. integrate the ‘paged’ parameter into the query.

    your chosen plugin seems to work only with the default query, not with custom queries.

    alternatively, have a look at http://wordpress.org/plugins/wp-pagenavi/ which is prepared for custom queries; see http://wordpress.org/plugins/wp-pagenavi/faq/Does PageNavi work with secondary WP_Query instances?‘ – applied to your case: wp_pagenavi( array( 'query' => $loop ) );

    Thread Starter Chris

    (@nutlog13)

    Ah, my bad. I had Grey Parrot’s query in there, but I had been trying different things and had changed ‘paged’ to ‘page’ (which some people on The Interwebs had said worked when using it on a page… but not for me).

    Anyway, changed ‘page’ in the query back to the original ‘paged’ and NOW your default WP prev/next pagination works fine. I’ll check out PageNavi as well; sounds like that will take care of it.

    Thank you very much for the help!

    Thread Starter Chris

    (@nutlog13)

    Yup, the WP-PageNavi plugin with the ‘paged’ query did the trick. Thanks guys! 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Why won't my pagination show up? (Custom Post Type)’ is closed to new replies.