-1

Question : how to display post count in a page like this picture : Showing 25 of 123 products

I mean in general. I use the custom theme and create a page that contains Categories. How to display text categories count per page for Categories Page. Example: Showing 25 of 123 products. 25 is the number of articles per page and 123 is the total articles for 1 category.

enter image description here

I have try used

Count Posts in a Category, Tag, or Custom Taxonomy plugin

by bitacre (shinraholdings.com).

wordpress.org/plugins/count-posts-in-a-category/

But it only show total count for all like this :

enter image description here

Using this shortcode :

Showing [tax_count tax="dt_portfolio_category" slug="products-banner"] products

How to modify it? I have ask in their forum and web but still no answer.

  • There have been a couple of these posts answered in the passed, so please use the site search, there are a couple of nice ideas on site – Pieter Goosen Oct 9 '15 at 11:26
  • hi @pieter-goosen, whether there are available as a plugin? I've been looking for in the form of plugins but I found everything is Post Views Count plugins. – Andhi Irawan Nov 26 '15 at 2:34
1

If you are asking about woocommerce, this function is located in woocommerce/templates/loop/results-count.php

Here's the full code, you will get the logic if you go through it.

$paged    = max( 1, $wp_query->get( 'paged' ) );
$per_page = $wp_query->get( 'posts_per_page' );
$total    = $wp_query->found_posts;
$first    = ( $per_page * $paged ) - $per_page + 1;
$last     = min( $total, $wp_query->get( 'posts_per_page' ) * $paged );

if ( 1 == $total ) {
    _e( 'Showing the single result', 'woocommerce' );
} elseif ( $total <= $per_page || -1 == $per_page ) {
    printf( __( 'Showing all %d results', 'woocommerce' ), $total );
} else {
    printf( _x( 'Showing %1$d&ndash;%2$d of %3$d results', '%1$d = first, %2$d = last, %3$d = total', 'woocommerce' ), $first, $last, $total );
}

It's called on archive template page through the following function:

do_action('woocommerce_before_shop_loop');

Or you can build your own. Getting programmatically the number of posts on archive page can be called through:

$display_count = get_option('posts_per_page');

and you can figure the rest.

  • thank you for your help.I tested your code in woocommerce page and it works. but I mean in general. I use the the7 theme and create a page that contains a collection of some of the articles / posts. how to display text post count. Example: Showing 25 of 123 products. 25 is the number of articles per page and 123 is the total articles for 1 category. I've changed my question to add this sentence. – Andhi Irawan Oct 13 '15 at 7:46
  • hi @koko5678, whether there are available as a plugin? I've been looking for in the form of plugins but I found everything is Post Views Count plugins. – Andhi Irawan Nov 26 '15 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.