php - 如何使用帖子元显示我的索引页帖子?
问题描述
我尝试在我的索引页面中显示我的帖子,因为这个原因我做了一个这样的 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();?>
这很棒而且很有效,但是对于分页我有很大的问题!它不工作!我可以自定义我的索引页查询吗?如何在保持分页正常工作的情况下进行此自定义?
解决方案
快速示例:
$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( '« PREV', $recent->max_num_pages) ?></li>
<li><?php next_posts_link( 'NEXT »', $recent->max_num_pages) ?></li>
</ul>
</nav>
<?php wp_reset_query(); ?>
希望能帮到你。
推荐阅读
- node.js - 如何正确检测中间件中的混合操作
- linux - bash每行打印带有分隔符的连续数字
- pandas - 将文本列转换为二进制,其中一组值 = 1,所有其他值 = 0
- php - 无法在php上打印数组或子数组
- android-recyclerview - Android Studio:将用户添加到 WhatsApp 等群组
- python - TensorFlow 2.0 中的 tf.contrib.layers.recompute_grad 在哪里?
- c# - 重定向到操作并打开新页面
- java - 如何从 API 向最终用户显示错误消息?
- python - 如何在 Python 中构建此图?
- java - Dagger2 - 应用程序不能依赖多个作用域组件