【问题标题】:I wanted to design my loop like this:我想这样设计我的循环:
【发布时间】:2018-12-05 21:39:44
【问题描述】:

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

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

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

【问题讨论】:

  • 你能分享更多细节吗?它是自定义注册分类法还是默认分类法?您希望在此处设置的类别。
  • 我将在那里定义任何 cate id.. 我只需要代码..

标签: wordpress loops posts


【解决方案1】:

在你的文件中试试这个代码

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

【讨论】:

  • 但我需要有人修改我的代码。在我的代码中我可以通过粘贴此代码来指定类别吗?
  • 只需粘贴我的代码并更改 id 72 而不是您的
  • 我在我的代码中有一种挑衅的风格..mu循环设计第一个带有缩略图的帖子,其他5个帖子没有任何标题..我想要那样..你明白吗?
猜你喜欢
  • 2022-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-14
  • 1970-01-01
  • 1970-01-01
  • 2020-08-14
相关资源
最近更新 更多