首页 > 解决方案 > 我想这样设计我的循环:

问题描述

我有一个循环代码,它显示第一个帖子有缩略图而其他帖子不包含它的帖子。但我想把它放在一个特定的类别中。
我的循环如下所示:

    <div class="category">
    <ul>
<!-- Start the Loop. -->
 <?php $i = 1 ; ?>
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <!-- Display the Title as a link to the Post's permalink. -->
 <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php if ($i == 1): ?>
<?php the_post_thumbnail();?>
<?php endif; ?>
<?php $i++; endwhile; endif; ?>
</ul>
</div>

所以我想用相同样式的特定类别来显示这个..

标签: wordpressloopsposts

解决方案


在您的文件中尝试此代码

<?php $catquery = new WP_Query( 'cat=72&posts_per_page=-1' );  ?>

    <ul>
        <?php 
            while($catquery->have_posts()) : $catquery->the_post(); 
        ?>
            <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
            <li><?php the_content(); ?></li>
        <ul>
        <?php endwhile; ?> 
    </ul>
<?php wp_reset_postdata(); ?>

推荐阅读