Support » Fixing WordPress » Bizarre next_posts_link/previous_posts_link problem

  • Hi folks, got a weird problem I’m hoping someone can help me out with.

    To see the problem, go to this site and note the “previous post” link at the bottom of the entry:

    http://cinemagogue.com

    If you click on that link, it takes you to the next post and also gives you a previous post link, and you can navigate through all of the posts on the site as expected.

    BUT, if you click on one of the post links in the sidebar, the post doesn’t have those links. The ul they are supposed to appear in is empty.

    Here’s the code I’m using in both home.php and single.php:

    <?php if (show_posts_nav()) : ?>
    <div class=”pagination”>

      <li class=”prevlink”><?php next_posts_link(‘Previous Post’); ?>
      <li class=”nextlink”><?php previous_posts_link(‘Next Post’); ?>

    </div>
    <?php endif; ?>

    And here’s the code from the functions.php file:

    function show_posts_nav() {
    global $wp_query;
    return ($wp_query->max_num_pages > 1);
    }

    Any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • That’s probably not bizzare behavior; I think that’s how your theme works with single posts that use page.php, as opposed to posts on single.php or home.php. Make a new page template for page.php and add the link code:

    http://codex.wordpress.org/Pages#Page_Templates

    Thread Starter tactics

    (@tactics)

    Page.php is used for permalink pages, not posts. So in the case of this site, it would be pages like:

    http://cinemagogue.com/about/

    But to test your theory, I added the code to page.php, and it didn’t work.

    Hmm. Don’t know. Do you have a posts loop on page.php?

    Thread Starter tactics

    (@tactics)

    Yep.

    <?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    <h1 class=”pageTitle”><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php edit_post_link(‘Edit this page’, ‘<p>’, ‘</p>’); ?>
    <?php if (show_posts_nav()) : ?>
    <div class=”pagination”>

      <li class=”prevlink”><?php next_posts_link(‘Previous Post’); ?>
      <li class=”nextlink”><?php previous_posts_link(‘Next Post’); ?>

    </div>

    This might not be quite your problem, but –

    I saw a similar probem addressed on another blog while trying to figure out why my custom query on a template page showed previous_posts_link, but not next_posts_link.

    You might try this for your next_posts_link code:

    <?php next_posts_link('next &raquo;', $wp_query->max_num_pages) ?>

    It worked in my case. HTH.

    Hi folks, I’m using WP 2.9.1 I was having a similar issue to this guy…

    http://wordpress.org/support/topic/232483?replies=2

    I applied css styling to the li’s and then I saw they were showing up visually when not necessary with no text in them yet. So I needed conditional code for them to show up…

    I ended up combining these two concepts:
    http://www.ericmmartin.com/conditional-pagepost-navigation-links-in-wordpress-redux/

    http://digwp.com/2009/12/optimizing-wordpress-post-navigation/

    to check for 3 specific cases:

    1. I am NOT on the first page of posts, and they’re more posts to looks at.

    2. Am I at the end?

    3. I’m on the first page.

    I commented out code, that other people might need:

    <?php if (($paged < $wp_query->max_num_pages) && ($paged > 1)) {// this checking max # of pages that are NOT page 1 ?>
    
    					<div class="navigation">
    						<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    						<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    					</div>
    
    				<?php } elseif ($wp_query->max_num_pages == $paged) {//this is checking for the LAST page in pagination ?>
    
    						<div class="navigation">
    							<!--<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>-->
    							<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    						</div>
    
    				<?php } else {// this is checking for the 1ST page in pagination ?>
    
    					<div class="navigation">
    						<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    						<!--<div class="alignright"><a href="<?php bloginfo('url'); ?>/archives/">Site Archives &raquo;</a></div>-->
    					</div>
    
    				<?php } ?>

    I know this is a bit inelegant, but it works.

    @chrsdgtl

    Thank you so much for that! I registered just to post this. I’ve been working all day trying to figure out how to do something as simple as having customized “next” or “prev” links not display on the first or last page. I even came across those sites you linked but could never get it 100%. Your post had me up and running in 10 seconds.

    If anyone is using images or CSS sprite style rollovers for their previous_post_link and next_posts_link then this is the only code you need.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Bizarre next_posts_link/previous_posts_link problem’ is closed to new replies.