我试图列出一组符合分类术语的产品。产品清单很好,但是I can\'t figure out the pagination of my custom posts. 我一直在谷歌、这里和许多其他地方寻找信息,没有结果。我甚至不知道如何解决这个问题。我的wordpress文件名为:分类学物种seefood。php该文件负责列出seefood动物,其代码为:
<?php
$paged = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1;
$posts_per_page = 6;
$offset = ( $paged - 1 ) * $posts_per_page;
$args = array(
\'post_type\' => \'products\',
\'post_parent\' => \'0\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'species\',
\'field\' => \'slug\',
\'terms\' => \'seefood\',
),
),
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'posts_per_page\' => $posts_per_page,
\'post_status\' => array(\'publish\', \'pending\', \'draft\'),
\'paged\' => $paged,
\'offset\' => $offset
);
$myposts = new WP_Query($args);
?>
<div role="main" id="content" class="content-wrap">
<div class="container">
<div id="primary" class="content-area col-md-12 post-list">
<?php
echo \'<main \';
if ( $myposts->have_posts() ) {
echo \' itemscope itemtype="http://schema.org/Blog" \';
}
echo \' id="main" class="site-main" role="main">\';
if ( $myposts->have_posts() ) {
echo \'<header class="page-header">\';
echo \'</header>\';
echo \'<div class="flex-items">\';
while ( $myposts->have_posts() ) {
$myposts->the_post();
/**
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( \'content\', get_post_type() );
}
echo \'</div>\';
wp_reset_postdata();
wpbeginner_numeric_posts_nav($myposts);
} else {
get_template_part( \'content\', \'none\' );
}
?>
功能
wpbeginner_numeric_posts_nav($myposts) 很好,它是从
https://www.wpbeginner.com/wp-themes/how-to-add-numeric-pagination-in-your-wordpress-theme/我认为我的$args变量是正确的,但一点也不确定。
如有任何建议,将不胜感激。我有一个小街区。
非常感谢。