Title: Problem with posts_nav_link()
Last modified: August 19, 2016

---

# Problem with posts_nav_link()

 *  [FGazerro](https://wordpress.org/support/users/fgazerro/)
 * (@fgazerro)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/)
 * Hey guys,
 * I’m running version 2.5.1.
 * I can’t get posts_nav_link() to work. I’ve tried putting it all over index.php
   and it never seems to work. The page loads but with no links. However, if i enclose
   it in paragraph tags it does create the extra space (but with no links). If ya’ll
   want I’ll post my entire index.php or loop.php. Any suggestions or maybe an explanation
   of posts_nav_link() that a five year old could understand would be awesome. Thanks.
 * Frank

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

 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774255)
 * Here’s the link to the documentation if that helps:
    [http://codex.wordpress.org/Template_Tags/posts_nav_link](http://codex.wordpress.org/Template_Tags/posts_nav_link)
 * I typically put my code for the nav link after:
 *     ```
       <?php endwhile; ?>
       ```
   
 * but before:
 *     ```
       <?php else : ?>
       ```
   
 * Without seeing your `index.php` code and how it works, this is as basic as it
   can get. A URL to your site might also help.
 *  Thread Starter [FGazerro](https://wordpress.org/support/users/fgazerro/)
 * (@fgazerro)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774326)
 * Hey there,
 * Thanks for responding. My site is FrankGazerro.com. Its not done yet but its 
   functional (for the most part). Below I’ll paste the index.php code. Thanks for
   your help.
 * here’s the code:
 *     ```
       <?php if (have_posts()) { ?>
   
       <div id="content">
   
       <?php
       	$postCount = 0;
       	$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
       	query_posts( 'paged=$page&showposts=10&post_per_page=-1&cat=' . get_query_var('cat') );
       	while (have_posts()) { the_post();
       		if( $postcount == 0 ) {
       		//GETS LATEST POST
       ?>
   
       		<div id="latest" class="entry">
   
       			<div class="clearfloat">
       				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
   
       				<div class="calendar">
       					<?php the_time('l');?>,
       					<?php the_time('F'); ?>
       					<?php the_time('j'); ?>
       					<?php the_time('Y'); ?></div>
   
       				</div>
   
       				<p class="frontcat"><?php the_category(', ') ?> </p>
   
       				<?php the_content(); ?>
   
       				<div class="commentcount"><p><?php comments_popup_link('0 Comments', '1 Comments', '% Comments');?></p></div>
   
       			</div>
   
       <?php
       		}
       		elseif( $postcount > 0 && $postcount <= 3 ) {
       		//GETS NEXT THREE EXCERPTS
       		?>
   
       		<div class="excerpt">
       			<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
   
       			<div class="calendar">
       				<?php the_time('l');?>,
       				<?php the_time('F'); ?>
       				<?php the_time('j'); ?>
       				<?php the_time('Y'); ?>
       			</div>
   
       			<p class="frontcat"><?php the_category(', ') ?> </p>
   
       			<?php the_content(); ?>
   
       			<div class="commentcount"><p><?php comments_popup_link('0 Comments', '1 Comment', '% Comments');?></p></div>
   
       		</div>
   
       <?php
       		}
       		else {
       			ob_start();
       			echo '<li>&raquo; <a href="';
       			the_permalink();
       			echo '">';
       			the_title();
       			echo '</a></li>';
       			$links[] = ob_get_contents();
       			ob_end_clean();
       		}
       		$postcount ++;
       		}
       	}
   
       ?>
   
       </div>
       ```
   
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774346)
 * I haven’t tested this, but I tried to clean up your code a bit to make it more
   readable, so that I could understand what’s going on.
 * I uploaded the code here:
 *     ```
       http://justintadlock.com/blog/wp-content/uploads/2008/05/problem-with-posts-nav.txt
       ```
   
 * Let me know how this works.
 *  Thread Starter [FGazerro](https://wordpress.org/support/users/fgazerro/)
 * (@fgazerro)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774407)
 * Hey there,
 * Thanks for your help with this. I replaced my code with yours. Unfortunately 
   it still didn’t work. Any other thoughts?
 * I appreciate your help.
 * Frank
 *  [Kalon](https://wordpress.org/support/users/kalon/)
 * (@kalon)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774412)
 * Note this will only show up if there are previous/future posts etc to display…
   I can only see one post on your site.
 *  Thread Starter [FGazerro](https://wordpress.org/support/users/fgazerro/)
 * (@fgazerro)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774429)
 * Greenshady and Kalon,
 * I worked a bit with the code that Greenshady gave me and i added a bunch of posts
   to make sure there would be something to link to. I encountered two problems.
 * First, the nav links still aren’t there. Second, for some reason the footer and
   the sidebar appeared inside the posts area underneath them. To fix this I added
   a handful of </div>’s to the bottom of index.php. Any thoughts? I really appreciate
   the help.
    -Frank Here’s the code:
 * <?php get_header(); ?>
 * <?php
    $postCount = 0; $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’):
   1; query_posts(‘paged=$page&showposts=10&post_per_page=-1&cat=’ . get_query_var(‘
   cat’)); ?>
 * <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
 * <div id=”content”>
 *  <?php if($postcount == 0) : ?>
 *  <div id=”latest” class=”entry”>
 *  <div class=”clearfloat”>
    <h2>” rel=”bookmark” title=”Permanent Link to <?php
   the_title_attribute(); ?>”><?php the_title(); ?>
   </h2>
    <div class=”auth”> <?
   php the_author() ?> </div>
 *  <div class=”calendar”>
    <?php the_time(‘l, F j Y’);?> </div>
 *  <span class=”frontcat”><?php the_category(‘, ‘) ?> </span>
 *  <?php the_content(); ?>
 *  <div class=”commentcount”><p><?php comments_popup_link(‘0 Comments’, ‘1 Comment’,‘%
   Comments’);?></p></div>
 *  <script src=”[http://feeds.feedburner.com/~s/FrankGBlog?i=&lt](http://feeds.feedburner.com/~s/FrankGBlog?i=&lt);?
   php the_permalink() ?>” type=”text/javascript” charset=”utf-8″></script>
 *  </div>
    </div>
 *  <?php elseif( $postcount > 0 && $postcount <= 3 ) : ?>
 *  <div class=”excerpt”>
    <h3>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute();?
   >”><?php the_title(); ?>
   </h3>
    <div class=”auth”> <?php the_author() ?> </div
   >
 *  <div class=”calendar”>
    <?php the_time(‘l, F j Y’);?> </div>
 *  <span class=”frontcat”><?php the_category(‘, ‘) ?> </span>
 *  <?php the_content(); ?>
 *  <div class=”commentcount”><p><?php comments_popup_link(‘0 Comments’, ‘1 Comment’,‘%
   Comments’);?></p></div>
 *  <script src=”[http://feeds.feedburner.com/~s/FrankGBlog?i=&lt](http://feeds.feedburner.com/~s/FrankGBlog?i=&lt);?
   php the_permalink() ?>” type=”text/javascript” charset=”utf-8″></script>
    </div
   >
 *  <?php else : ?>
    -  <?php
       ob_start(); echo ‘
    - » [‘; the_title(); echo ‘](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/&apos;; the_permalink(); echo &apos;?output_format=md)
    - ‘;
       $links[] = ob_get_contents(); ob_end_clean(); ?>
 *  <?php endif; ?>
 * <?php $postcount++; endwhile; ?>
 *  <div class=”navigation-links”>
    <?php posts_nav_link(”,'<span class=”previous”
   >« Previous Page</span>’,'<span class=”next”>Next Page »</span>’); ?> </div> 
   </div>
 * <?php endif; ?>
    </div> </div> </div> </div> </div>
 * <?php get_sidebar(); ?>
 * <?php get_footer(); ?>
 *  [iridiax](https://wordpress.org/support/users/iridiax/)
 * (@iridiax)
 * [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774430)
 * I tried [http://www.frankgazerro.com/page/2/](http://www.frankgazerro.com/page/2/)
   and I got a 404 (Not Found) error.

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

The topic ‘Problem with posts_nav_link()’ is closed to new replies.

 * 7 replies
 * 4 participants
 * Last reply from: [iridiax](https://wordpress.org/support/users/iridiax/)
 * Last activity: [18 years ago](https://wordpress.org/support/topic/problem-with-posts_nav_link-1/#post-774430)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
