dongping1922 2014-06-13 13:59
浏览 23
已采纳

自定义帖子类型上的无限帖子

I've got a custom post type I need to set to 'display all posts'. In Reading I've set it to 10 due to only wanting 10 posts on the blog page. How do I set the maximum posts on the CPT page? I've found this code...

$args = array('post_type' => 'portfolio',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'portfolio',
'field' => 'slug',
)
)
)

$query = new WP_Query($args)

I'm new to php so I'm unsure where I add this - functions.php in the 'register CPT' or in the loop on the archive page? The loop is quite complicated as I'm pulling in 3 taxonomies and setting values each time.

<?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; ?>

Any help would be appreciated, thanks.

  • 写回答

2条回答 默认 最新

  • dreamy6301 2014-06-13 14:42
    关注

    I figured it out, I used this:

    <?php $args = array( 'post_type'=>'portfolio', 'posts_per_page'=>100); 
                        $portfolio = new WP_Query( $args ); while( $portfolio->have_posts() ) : $portfolio->the_post(); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器