我有一个自定义帖子类型,我需要设置为“显示所有帖子”。在阅读中,由于只想在博客页面上发布10个帖子,我将其设置为10。如何在CPT页面上设置最大帖子?我找到了这段代码......
$args = array('post_type' => 'portfolio',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'portfolio',
'field' => 'slug',
)
)
)
$query = new WP_Query($args)
我是php的新手,所以我不确定我在“寄存器CPT”或存档页面的循环中添加了 - functions.php?循环非常复杂,因为我每次都要划分3个分类并设置值。
<?php $i = 0; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$i++;
$term_list1 = wp_get_post_terms($post->ID, 'discipline', array("fields" => "ids"));
$term_list2 = wp_get_post_terms($post->ID, 'type', array("fields" => "ids"));
$term_list3 = wp_get_post_terms($post->ID, 'sector', array("fields" => "ids"));
?>
<li class="item" data-id="id-<?php echo $i; ?>" data-type='<?php foreach ($term_list1 as $value) {echo $value." ";} ?><?php foreach ($term_list2 as $value) {echo $value." ";} ?><?php foreach ($term_list3 as $value) {echo $value." ";} ?>'>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
</li>
<?php endwhile; else : ?>
<?php endif; ?>
任何帮助将不胜感激,谢谢。
答案 0 :(得分:1)
我弄清楚了,我用过这个:
<?php $args = array( 'post_type'=>'portfolio', 'posts_per_page'=>100);
$portfolio = new WP_Query( $args ); while( $portfolio->have_posts() ) : $portfolio->the_post(); ?>
答案 1 :(得分:0)
您需要编辑模板,并在循环之前将这些参数传递给query_posts
函数,然后在wp_reset_query
之后重置查询:
<?php
query_posts( array(
'post_type' => 'portfolio',
'posts_per_page' => -1 )
);
$i = 0;
if (have_posts()) : while (have_posts()) :
the_post();
$i++;
$term_list1 = wp_get_post_terms($post->ID, 'discipline', array("fields" => "ids"));
$term_list2 = wp_get_post_terms($post->ID, 'type', array("fields" => "ids"));
$term_list3 = wp_get_post_terms($post->ID, 'sector', array("fields" => "ids"));
?>
<li class="item" data-id="id-<?php echo $i; ?>" data-type='<?php echo implode(' ',$term_list1 ) . ' ' . implode(' ',$term_list2 ) . ' ' . implode(' ',$term_list3 ); ?>'>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
</li>
<?php
endwhile; endif;
wp_reset_query();
?>
我还使用implode而不是foreach循环来完成数据类型的生成