WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Nesting navigation within a $count loop (8 posts)

  1. toxiccosmos
    Member
    Posted 5 months ago #

    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/

    The code: 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 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.

  2. toxiccosmos
    Member
    Posted 5 months ago #

    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.

  3. alchymyth
    The Sweeper & Moderator
    Posted 5 months ago #

  4. toxiccosmos
    Member
    Posted 5 months ago #

    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. :/

  5. toxiccosmos
    Member
    Posted 5 months ago #

    Here is an update of the entire Index:
    http://pastebin.com/SHZsLeJT

  6. alchymyth
    The Sweeper & Moderator
    Posted 5 months ago #

    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

  7. toxiccosmos
    Member
    Posted 5 months ago #

    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 :)

  8. toxiccosmos
    Member
    Posted 5 months ago #

    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

Reply

You must log in to post.

About this Topic