WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Previous and Next nav links don’t show up

[Resolved] Previous and Next nav links don’t show up

  • not sure but my next and previous navigation links don’s show up.

    I am using <?php $my_query = new WP_Query('category_name=blog&posts_per_page=4');

    just above this line I have:

    <div class="navigation">
    			<div class="alignleft"><?php next_posts_link('next') ?></div>
    			<div class="alignright"><?php previous_posts_link('prev') ?></div>
    		</div>

    and I see just blank space there.

Viewing 10 replies - 1 through 10 (of 10 total)
  • I believe the query has to be completed before the previous/next_posts_links can be created.

    Michael

    @alchymyth

    Forum Moderator

    i tried this in my test setup, local, and the query did not seem to influence the next/prev posts links.

    are you using this in index.php?
    did the links show before you put that code there?

    theme?

    link to your site?

    I use it in my custom template file

    Here is the link to the site:
    http://lhaworld.bolderimage.com/blog-page/

    Michael

    @alchymyth

    Forum Moderator

    thanks @vtxyzzy, you are right:

    because it is a custom template (different from index.php), the next/prev posts links have to come after the query.

    @krystiank:
    you also may need the ‘paged’ parameter to get pagination working.

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=blog&posts_per_page=4&paged='.$paged); ?>
    
    <div class="navigation">
    			<div class="alignleft"><?php next_posts_link('next') ?></div>
    			<div class="alignright"><?php previous_posts_link('prev') ?></div>
    		</div>

    Thanks a lot. I will try that. So basically there is no way to add the navigation on the top of the page?

    Sure there is. Just because the query has to be called before the nav, doesn’t mean that you have to use it at that point in the page. Just start the Loop after you have completed whatever else you want done.

    Michael

    @alchymyth

    Forum Moderator

    you can always put the query directly at the beginning of your template, before any content and before the navigation.

    that could obviously be difficiult or impossible, depending on how your template is structured.

    This is my final code. It works now. Thanks a lot guys.

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=blog&posts_per_page=4&paged='.$paged); ?>
    
    <div class="navigation">
    			<div class="alignleft"><?php next_posts_link('next') ?></div>
    			<div class="alignright"><?php previous_posts_link('prev') ?></div>
    </div>
    
     <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    	<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    	<h2>Posted by: <?php the_author() ?> on  <?php the_time('F j, Y'); ?> at <?php the_time('g:i a T'); ?></h2>
    	<?php global $more; $more = 0; ?>
    	<p><?php the_content('... Read More >>'); ?></p>
    	<p class="postmetadata"><?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    
     <?php endwhile; else: ?>
     <p>Sorry, no posts matched your criteria.</p>
     <?php endif; ?>

    You are welcome! Now, please mark this topic ‘Resolved’.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Previous and Next nav links don’t show up’ is closed to new replies.
Skip to toolbar