繁体   English   中英

Posts_per_page类别wordpress显示1个帖子,而不是多个

[英]Posts_per_page category wordpress showing 1 post instead of multiple

我想我的循环做错了什么,或者我的代码坏了。 我想显示特定类别的所有帖子。 无论我做什么,我只会看到1条帖子。

<ol>

    <?php
    $args = array(
       'category_name'=>'test-category',
       'posts_per_page' => 15,
       'nopaging' => true
    );
    $query = new WP_Query( $args );
    while ( $query->have_posts() ) : $query->the_post();
        //Post data
        echo get_the_post_thumbnail(get_the_ID());
    endwhile;
    ?>

                                            <li data-href="<?php $trink = get_the_permalink(); echo preg_replace("#/$#im", '', $trink);?>">
                        <div>
                            <a class="button" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        </div>
                    </li>

    </ol>

我在这里做错了什么?

你的endwhile; 位置错误:构建<li>标签的代码不在循环中,这就是为什么只看到一篇文章的原因。

它应该是:

<ol>

<?php
$args = array(
    'category_name' => 'test-category',
    'posts_per_page' => 15,
    'nopaging' => true
);
$query = new WP_Query( $args );

while ( $query->have_posts() ) : $query->the_post();
    //Post data
    echo get_the_post_thumbnail(get_the_ID());
?>

    <li data-href="<?php $trink = get_the_permalink(); echo preg_replace("#/$#im", '', $trink);?>">
        <div>
            <a class="button" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
         </div>
     </li>

<?php
endwhile;
?>
</ol>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM