• I have my homepage showing posts from a specific category. I want to add a link at the bottom to go to Older or Newer entries. I’m trying to use posts_nav_link but the second page keeps returning posts in other categories.

    Can someone help take a look at my page and tell me why it returns posts in other categories? I’ve been trying for awhile now and can’t figure it out. My blog is https://eatsmilesleep.com. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • If you’re using a custom query (and it sounds like you are), it needs to be edited to take paging into account – eg:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category_name' => 'News',
    	'paged' => $paged
    );
    query_posts($args);
    ?>
    Thread Starter sweetflame

    (@sweetflame)

    Hmm I added that but it didn’t seem to help. Can you help me take another look? Thanks for your suggestion.

    Drop a copy of index.php into the WordPress pastebin and post the pastebin url here. Perhaps we’ll will be able to spot the problem and suggest a solution.

    Thread Starter sweetflame

    (@sweetflame)

    This is my index.php: https://wordpress.pastebin.com/m1zRVkSC

    But for my home page, I’m using a template (main.php). Here it is: https://wordpress.pastebin.com/CKaqpZnk

    Thank you!

    Is your home page a static page?

    I’ve just checked the code for main.php and it looks fine – although you might want to think about setting a posts_per_page limit into that custom query. I also had a look at your site’s Home page and I couldn’t see a single post on there that wasn’t in the Eat category.

    Are you remembering to press CTRL and F5 simultaneously when viewing the updated page? Or emptying your browser cache? This should ensure that your web browser fetches a fresh copy of the page rather than serving up an out-dated copy from your own cache.

    Thread Starter sweetflame

    (@sweetflame)

    It’s not the first page that’s giving me a problem – when I try to click to the Next Page (at the bottom), it brings up entries that are in a different category. I want them to be the next pages in the same “Eat” category. I hope that makes sense..

    And yeah, my home page is a static page.

    The main.php template should be doing just that – which suggests that perhaps there’s another Loop on the page that’s throwing everything out. The left-sidebar.php file might be a good place to start looking.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘posts_nav_link Category’ is closed to new replies.