• Hi, I want to show my one cat’s total post numbers

    Like 1 to 20 of 100
    If possible, I’m willing to dinamic the 1 and 20 100,
    1 means first post,
    20 means the 20th post,
    100 means the total posts in that cat

    If I have pagination, that in pages 2, it should be 21 to 40 of 100

    How could I modified my codes.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Getting the total category count is fairly easy:

    $cat = get_the_category();
    $cat = $cat[0];
    $category_count = $cat->category_count;

    Dynamically outputting the current range might be slightly more tricky. Maybe combine the above code with something like this (completely untested):

    global $paged, $posts_per_page;
    
    $current_page = ( $paged ? $paged : '1' );
    $current_min = ( $paged > 1 ? $paged * ( $posts_per_page - 1 ) + 1 : '1' );
    $current_max = ( $paged > 1 ? $paged * $posts_per_page : $category_count );
    
    echo $current_min . ' to ' . $current_max . ' of ' . $category_count;

    Thread Starter mmson

    (@mmson)

    Thank you Chip Bennett
    I read your code it seeds to count the total category, but I just want to count one category’s posts, sorry for my title mistake.

    such as games category, there are 10 posts in the games cat, I want to show the posts total number on my site, is it possible?

    I read your code it seeds to count the total category, but I just want to count one category’s posts

    That’s what this should do:

    $cat = get_the_category();
    $cat = $cat[0];

    The call to get_the_category() will return an array with all the categories, each as an object.

    The call to $cat[0] will pull out the first object in the array, i.e. the first category.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to display one cat's total numbers’ is closed to new replies.