Wrong post count in pagination (2 posts)

  1. jezzoo
    Posted 7 years ago #

    I want to show on my main page post from only one category so I wrote something like this in index.php:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if (in_category('cat_number'))

    but limitation in_category() inside the loop cause problem with post counting. posts_nav_link() on last page show "next page>>" like it should be next page witg post but it isn't. On click on "next page>>" empty page is showing. I am sure this is caused by counting posts witch are not in category limited by in_category().
    How should I wrote loop to posts_nav_link work correctly.

  2. MichaelH
    Posted 7 years ago #

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat='. $cat . '&paged=' . $paged);
    if (have_posts()) : while (have_posts()) : the_post();

    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Topic Closed

This topic has been closed to new replies.

About this Topic