php仅循环5次,每次发布应循环一次

时间:2018-07-09 21:15:17

标签: php wordpress

我不精通php,所以也许我忽略了一些简单/愚蠢的东西。

但是下面的代码似乎只循环5次(至少只输出5个站点),例如,这个特定类别中有12个站点。

我做错什么了吗?

<div class="col-md-3">
<div class="maddos-category-container">
<div class="maddos-category-header"><h3 class="maddos-category-header-title"><a href="<?php echo get_category_link( "17" );?>"><?php echo get_cat_name(17);?></a></h3></div>
<div class="maddos-category-wrapper">
<ol>
   <?php
    $args = array( 'category' => 17, 'post_type' =>  'post' ); 
    $postslist = get_posts( $args );    
    foreach ($postslist as $post) :  setup_postdata($post); 
    ?>  
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
    <?php endforeach; ?> </div></div></div>
</ol>

1 个答案:

答案 0 :(得分:2)

看看get_posts的文档

  

$ args

     

(数组)(可选)用于检索帖子的参数。有关所有可用参数,请参见WP_Query :: parse_query()。

     

“数字帖子”   (int)要检索的帖子总数。是WP_Query中$ posts_per_page的别名。接受-1。默认值5。

因此,替换:

$args = array( 'category' => 17, 'post_type' =>  'post' ); 

使用

$args = array( 'category' => 17, 'post_type' =>  'post',  'numberposts' => -1);  //unlimited