WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Previous and Next nav links don't show up (11 posts)

  1. krystiank
    Member
    Posted 4 years ago #

    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.

  2. vtxyzzy
    Member
    Posted 4 years ago #

    I believe the query has to be completed before the previous/next_posts_links can be created.

  3. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    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?

  4. krystiank
    Member
    Posted 4 years ago #

    I use it in my custom template file

  5. krystiank
    Member
    Posted 4 years ago #

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

  6. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    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>
  7. krystiank
    Member
    Posted 4 years ago #

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

  8. vtxyzzy
    Member
    Posted 4 years ago #

    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.

  9. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    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.

  10. krystiank
    Member
    Posted 4 years ago #

    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; ?>
  11. vtxyzzy
    Member
    Posted 4 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.