首页 > 解决方案 > 如何使用帖子元显示我的索引页帖子?

问题描述

我尝试在我的索引页面中显示我的帖子,因为这个原因我做了一个这样的 wp 查询:

 <?php $recent = new WP_Query(
        array(
        'posts_per_page' => 5,
        'post_type' => 'post',
        'meta_key' => 'post-filter-select',
        'meta_value' => 'music'));

 while($recent->have_posts()) : $recent->the_post();?>

这很棒而且很有效,但是对于分页我有很大的问题!它不工作!我可以自定义我的索引页查询吗?如何在保持分页正常工作的情况下进行此自定义?

标签: phpwordpresspagination

解决方案


快速示例:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'posts_per_page' => 5,
    'paged' => $paged,
    'post_type' => 'page',
    'meta_value' => 'music'
);
$recent = new WP_Query($args);
?>
<?php if ($recent->have_posts()) : while ($recent->have_posts()) : $recent->the_post(); ?>

    // loop

<?php endwhile; endif; ?>
<nav>
    <ul>
        <li><?php previous_posts_link( '&laquo; PREV', $recent->max_num_pages) ?></li>
        <li><?php next_posts_link( 'NEXT &raquo;', $recent->max_num_pages) ?></li>
    </ul>
</nav>
<?php wp_reset_query(); ?>

希望能帮到你。


推荐阅读