• Ok. I am going a little crazy over this. The next and previous links don’t show up in my custom loop, which is on a page template (not the home page). I’ve looked at several posts on this board and others, and none of the solutions seem to work for me.

    If I echo out the $page var I get the default 1, so I figure I must be missing some global… Any help will be much appreciated.

    <?php
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$sgallery_loop = new WP_Query( array("post_type" => "galleries", "post_status" => "published", "paged" => $paged, "posts_per_page" => "1", "caller_get_posts" => 1) );
    ?>
    <?php while ( $sgallery_loop->have_posts() ) : $sgallery_loop->the_post(); ?>
    <nav class="postnav">
    	<div class="older">
    		<p><?php next_posts_link('&laquo; Older Entries') ?></p>
    	</div>
    	<div class="newer">
    		<p><?php previous_posts_link('Newer Entries &raquo;') ?></p>
    	</div>
    </nav>
    
    	<div id="galllery-<?php echo $sectionID; ?>" class="section">
    		<h3><?php the_title(); ?></h3>	
    
    <?php endwhile; ?><!-- End Gallery Loop -->

    Links to other posts
    https://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/
    https://www.ads-software.com/support/topic/pagination-with-custom-post-type-listing
    https://www.ads-software.com/support/topic/custom-posts-pagination

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter artfulalibi

    (@artfulalibi)

    Anyone?

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it without the quotes: “posts_per_page” => 1,

    and try it with the next_posts_link and previous_posts_link after the loop.

    Thread Starter artfulalibi

    (@artfulalibi)

    Thanks for catching the syntax issue. I moved the next/previous links back down, I only moved them up in the paste above, which is obviously wrong.

    But it didn’t fix the issue. And paged still echos out as 1. Which lead me to try simply assigning $paged = 3. This created a next page link, but broke the loop content ~ no title was created.

    Thread Starter artfulalibi

    (@artfulalibi)

    Ok. I have it working now. But I am a little dissatisfied with the answer. This code was a template part from another page where I have multiple loops. But this page does not, so I set the query up to be the standard query with arg instead of the $gallery = WP_Query, and the whole thing works.

    Thanks for you help Keesie.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Next/Previous links in a custom post loop not showing up’ is closed to new replies.