在自定义帖子类型分类 WordPress 中显示 x of y 帖子


Showing x of y posts in custom post type taxonomy WordPress

>我已经创建了一个自定义帖子类型,注册了它,并创建和注册了一个关联的自定义分类法。 我需要以某种方式对类别页面进行分页,例如"您正在查看此自定义分类法中 15 个帖子中的 1-10 个",然后在底部有一个指向这些页面的下一页的链接。

我的循环运行良好,如下所示:

<div class="simple-product-listing archive-box">
<?php while ( have_posts() ) : the_post(); ?>
<li>
    <div <?php post_class( $classes ); ?>>
        <a title="<?php the_title() ?>" href="<?php the_permalink(); ?>" data-toggle="tooltip">
            <div class="row catalog">
                <div class="col-md-6 col-md-push-6 arrow">
                    <?php if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail())) {
                        $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'dnf-cat' );
                        $url = $thumb['0'];
                    ?>
                    <div class="the-prod-image" style="background-image: url(<?=$url?>);"></div>
                    <?php } else { ?>
                    <div class="the-image-div" style="background-image: url(<?php bloginfo('template_directory'); ?>/images/default.svg);"></div>
                    <?php } ?>
                </div>
                <div class="col-md-6 col-md-pull-6 arrow">
                    <h3 class="post-box-title"><?php the_title(); ?></h3>
                    <div class="entry">
                        <i class="blog-title-border"></i>
                        <?php the_excerpt() ?>
                        <div class="btn btn-default btn-sm active text-uppercase" role="button" title="<?php the_title() ?>">Read More &raquo;</div>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </a>
    </div>
</li>
<?php endwhile;?>
</div>

到目前为止,我在分页显示方面所能弄清楚的只是:

<?php
    $pagenum = $query->query_vars['paged'] < 1 ? 1 :  $query->query_vars['paged'];
    $first = ( ( $pagenum - 1 ) * $query->query_vars['posts_per_page'] ) + 1;
    $last = $first + $query->post_count - 0;
    echo '<p class="results-count">Showing ' . $first . ' of ' . $last . ' products in this category</p>';
?>

但这不会显示高于 1 的"数字,也不能解决我想要的页面底部的分页项。

经过

相当多的搜索和反复试验,我找到了解决方案......

<?php
    // Number of products in category
    $pagenum = $query->query_vars['paged'] < 1 ? 1 : $query->query_vars['paged'];
    $first = ( ( $pagenum - 1 ) * $query->query_vars['posts_per_page'] ) + 1;
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    echo '<p class="results-count">Showing ' . $first . ' of ' .count($myposts = get_posts( $args )). ' products in this category</p>';
?>