我有一个自定义的分类法,它会列出与之相关的帖子列表。以前-在$posts_args
数组,我设置post_per_page
选项到-1
但是应该添加已实现的分页,以便在每篇文章中显示大量媒体。我读了一遍paginate_links() (并在下面的查询中添加了他们的示例),但到目前为止,还没有根据需要解析出帖子。现在-posts_per_page
设置为2
总的来说WordPress > Reading
设置(有效-页面上仅显示2篇帖子)和paginate_links()
函数调用实际上会根据每页的帖子和帖子总数生成所需的页面数量,但当我转到第二页(如/page/2)时,会显示与第一页相同的帖子。对我可能遗漏的内容有什么建议吗?谢谢
$post_args = array(
\'post_type\' => \'moulding_profiles\',
\'meta_key\' => \'_mouldings_dimensions_height\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => $taxfunc_tax_name,
\'field\' => \'id\',
\'include_children\' => 0,
\'terms\' => $term_id
)
)
);
$posts_query = new WP_Query($post_args);
$i = 0; // count
$total_items = $posts_query->post_count; // total profiles
$number_columns = $mouldings_options[\'profile_item_columns\']; // number of columns
if ($posts_query->have_posts() ) {
// Filter function
mouldings_profile_list_before();
echo \'<div id="mouldings-list">\';
while($posts_query->have_posts() && ($i < $total_items)) { ?>
<?php $posts_query->the_post(); if ($i % $number_columns == 0) echo ($i > 0 ? \'</div><div class="row">\' : \'<div class="row first-row">\'); ?>
<div class="<?php echo \'width\'.intval(100 / $number_columns); ?> <?php if ($i % $number_columns == 0) echo \'first-item\'; ?>">
<?php
moulding_profile_teaser($profile_ID = get_the_ID());
?>
</div>
<?php $i++;
}
echo \'</div>\';
echo \'</div>\';
mouldings_profile_list_after();
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\',
\'current\' => max( 1, get_query_var(\'paged\') ),
\'total\' => $posts_query->max_num_pages
) );
}
wp_reset_query();