Title: Nesting navigation within a $count loop
Last modified: August 21, 2016

---

# Nesting navigation within a $count loop

 *  Resolved [toxiccosmos](https://wordpress.org/support/users/toxiccosmos/)
 * (@toxiccosmos)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/)
 * Hey everyone,
 * So, I’m using `$count` to display my index in variable post styles (full width
   latest post highlight followed by left and right columns for the rest).
    [http://victoriaarriaga.com/test_site/](http://victoriaarriaga.com/test_site/)
 * The code: [http://pastebin.com/mDw0jSF1](http://pastebin.com/mDw0jSF1)
 * The problem I’m having is that my navigation isn’t working correctly. It is currently
   displaying “Page 1 of 1” despite the fact that there are enough posts for two
   pages.
 * I’m currently using the plugin [WP-PageNavi](http://wordpress.org/plugins/wp-pagenavi/)
   for my navigation, but I believe my problem lies with the way I have it nested
   within the loop. I was hoping someone could take a look at it and let me know
   if that’s the case.
 * It might be important to note that I also intend to put the navigation at the
   bottom of the page as well, so any needed special pointers in accomplishing that
   would be appreciated. 🙂
 * Thanks.

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

 *  Thread Starter [toxiccosmos](https://wordpress.org/support/users/toxiccosmos/)
 * (@toxiccosmos)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547634)
 * Update: I’ve also tried replacing the PageNavi code with the conventional
 *     ```
       <?php
       next_posts_link( 'Older Entries', $the_query->max_num_pages );
       previous_posts_link( 'Newer Entries' );
       ?>
       ```
   
 * and have tried moving it around within my loop to see if I have any luck in getting
   this to work properly, but haven’t been able to. I’m not very proficient in PHP,
   so I’m really at a loss now and would really appreciate some advice from those
   of you more knowledgeable than I.
 * Thanks.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547637)
 * try at least to add the `'paged'` parameter to the query;
 * [http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query](http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query)
 * [http://codex.wordpress.org/Pagination](http://codex.wordpress.org/Pagination)
 *  Thread Starter [toxiccosmos](https://wordpress.org/support/users/toxiccosmos/)
 * (@toxiccosmos)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547638)
 * Thanks for the reply, alchymyth.
 * That’s what I thought I was doing (adding the `paged` parameter) with:
    `$the_query
   = new WP_Query( array( 'posts_per_page'=> 5, 'paged' => $paged ) );`
 * But I see my mistake.
 * I’m not sure I’ve implemented it properly, but I now have:
 *     ```
       <?php $count = 0;
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $args = array(
       'posts_per_page' => 5,
       'paged' => $paged
       );
       $the_query = new WP_Query($args);
       ?>
       ```
   
 * If I’m not mistaken, that defines `$paged` and then sets it to use in the query,
   right? Though I don’t see that it has fixed the issue I’m having. Page 2 still
   seems to be the same as the first. :/
 *  Thread Starter [toxiccosmos](https://wordpress.org/support/users/toxiccosmos/)
 * (@toxiccosmos)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547640)
 * Here is an update of the entire Index:
    [http://pastebin.com/SHZsLeJT](http://pastebin.com/SHZsLeJT)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547642)
 * try with ‘page’:
 *     ```
       <?php $count = 0;
       $paged = (get_query_var('page')) ? get_query_var('page') : 1;
       $args = array(
       'posts_per_page' => 5,
       'paged' => $paged
       );
       $the_query = new WP_Query($args);
       ?>
       ```
   
 * if that also won’t work, please post the full code of the template; [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
 *  Thread Starter [toxiccosmos](https://wordpress.org/support/users/toxiccosmos/)
 * (@toxiccosmos)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547643)
 * That worked perfectly! Thank you! I’ve been banging my head for the past two 
   weeks trying to figure it out and you’ve fixed it for me in two hours. 🙂 I really
   appreciate it. Thanks 🙂
 *  Thread Starter [toxiccosmos](https://wordpress.org/support/users/toxiccosmos/)
 * (@toxiccosmos)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547658)
 * Just a quick note to anyone trying to get their navigation to work, I had to 
   use the following code to get the navigation to correctly display the current
   page being viewed:
 *     ```
       <?php $count = 0;
       if( get_query_var( 'paged' ) )
       	$my_page = get_query_var( 'paged' );
       else {
       	if( get_query_var( 'page' ) )
       		$my_page = get_query_var( 'page' );
       	else
       		$my_page = 1;
       	set_query_var( 'paged', $my_page );
       	$paged = $my_page;
       }
       	$paged = (get_query_var('page')) ? get_query_var('page') : 1;
       	$args = array(
       		'posts_per_page' => 5,
       		'paged' => $paged
       	);
       	$the_query = new WP_Query($args);
       ?>
       ```
   
 * I found this here: [http://wordpress.org/support/topic/wp-pagenavi-with-custom-query-and-paged-variable?replies=2](http://wordpress.org/support/topic/wp-pagenavi-with-custom-query-and-paged-variable?replies=2)

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

The topic ‘Nesting navigation within a $count loop’ is closed to new replies.

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [navigation](https://wordpress.org/support/topic-tag/navigation/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [toxiccosmos](https://wordpress.org/support/users/toxiccosmos/)
 * Last activity: [12 years, 4 months ago](https://wordpress.org/support/topic/nesting-navigation-within-a-count-loop/#post-4547658)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
