php - WordPress:posts_per_page 在存档页面上不起作用
问题描述
我有一个自定义循环,它应该以随机顺序显示每个类别的 3 个项目。问题是,循环总是显示该类别中的所有项目。
我已经在一个页面上测试了代码,它的工作方式应该是这样,并且只显示了 3 个项目。
所以我猜它与存档页面有关?!
这是循环本身:
<?php
$args_thema = array (
'post_type' => array( 'project' ),
'orderby' => 'rand',
'posts_per_page' => 3,
'paged' => $paged,
//'ignore_sticky_posts' => 1,
'tax_query' => array(
array(
'taxonomy' => 'project-category',
'field' => 'slug',
'terms' => $category->slug,
),
),
);
$query_thema = new WP_Query( $args_thema ); if ( $query_thema->have_posts() ) : ?>
<ul class="">
<?php $i = 0; while ( $query_thema->have_posts() ) : $query_thema->the_post(); $i++; // echo $i; ?>
<li class="">
<a class="url uid" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<?php endif; wp_reset_postdata(); ?>
这是完整的代码(我想不是那么相关):
<?php
$args = array('hide_empty' => '0', 'taxonomy' => 'project-category', 'orderby' => 'name', 'order' => 'ASC', 'parent' => 0 );
$categories = get_categories($args);
foreach($categories as $category) {
?>
<div class="row">
<div class="col-lg-4">
<?php
$term_child = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$args_child = array('hide_empty' => '0', 'taxonomy' => 'project-category', 'orderby' => 'name', 'order' => 'ASC', 'parent' => $category->term_id );
?>
<h4><a href="<?php echo get_term_link($category->slug, 'project-category') ?>" title="<?php echo $category->name ?>"><?php echo $category->name; ?></a></h4>
</div>
<div class="col-lg-8">
<?php
$args_thema = array (
'post_type' => array( 'project' ),
'orderby' => 'rand',
'posts_per_page' => 3,
'paged' => $paged,
//'ignore_sticky_posts' => 1,
'tax_query' => array(
array(
'taxonomy' => 'project-category',
'field' => 'slug',
'terms' => $category->slug,
),
),
);
$query_thema = new WP_Query( $args_thema ); if ( $query_thema->have_posts() ) : ?>
<ul class="">
<?php $i = 0; while ( $query_thema->have_posts() ) : $query_thema->the_post(); $i++; // echo $i; ?>
<li class="">
<a class="url uid" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<?php endif; wp_reset_postdata(); ?>
</div>
</div>
<?php } ?>
解决方案
抱歉,这是一个额外的功能,将存档帖子设置为 99。
而不是is_post_type_archive
我用is_archive
推荐阅读
- angular - 如何传递查询参数以加载基于角度路由加载的角度组件
- postgresql - 为什么我有这个问题:无法读取文件中的块问题?
- android - RecyclerView 获取特定位置的视图并从中检索数据 android kotlin
- shell - 使用 Xamarin.Forms Shell 从单个页面导航到主详细信息页面
- python - 在 python grok 中计算字符
- javascript - 如何组合来自不同 Promise 的参数?
- php - Apache + Chrome + PHP => 无限加载
- python - 为什么通过 url 循环获取页面源只能获取 url 页面源的一半?Python
- javascript - 收集 html 表单数据并作为 json 有效负载发送到 api
- javascript - Uppy 没有出现在 rails 应用程序的屏幕上