我已经在小部件中按类别获取自定义帖子类型。现在,如果超过 10 个帖子,我想对这些帖子进行分页。为此,我尝试使用此代码
<ul class="posts-list">
<?php
$cats = get_the_category();
$cat_name = $cats[0]->name;
$paged= isset( $_GET['paged1'] ) ? (int) $_GET['paged1'] : 1;
query_posts(array ( 'category_name' => $cat_name, 'posts_per_page' => 6, 'paged' => $paged));
while (have_posts()) : the_post();
// do whatever you want
?>
<li>
<h5><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h5>
<p><strong>posted on</strong> <?php the_time(' F jS, Y') ?> <strong>by</strong> <?php the_author(); ?></p>
<p><strong>Posted in</strong> <span><?php print_r($cat_name); ?></span></p>
<?php
endwhile;
?>
</li>
<?php
$pag_args1 = array(
'format' => '?paged=%#%',
'current' => $paged,
'total' => 3,
'add_args' => array( 'paged' => $paged)
);
echo paginate_links( $pag_args1 ); ?>
</ul>
但我无法得到确切的结果。