如果您询问woocommerce,此函数位于woocommerce/templates/loop/results count中。php
这是完整的代码,如果您仔细阅读,就会得到逻辑。
$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–%2$d of %3$d results\', \'%1$d = first, %2$d = last, %3$d = total\', \'woocommerce\' ), $first, $last, $total );
}
它通过以下函数在存档模板页面上调用:
do_action(\'woocommerce_before_shop_loop\');
或者你可以自己建造。可以通过以下方式以编程方式获取存档页面上的帖子数:
$display_count = get_option(\'posts_per_page\');
其余的你都能猜出来。