wordpress - 我想这样设计我的循环:
问题描述
我有一个循环代码,它显示第一个帖子有缩略图而其他帖子不包含它的帖子。但我想把它放在一个特定的类别中。
我的循环如下所示:
<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>
所以我想用相同样式的特定类别来显示这个..
解决方案
在您的文件中尝试此代码
<?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(); ?>
推荐阅读
- java - 使用 jni 将返回带有模板的对象的 java 代码转换为 c++
- javascript - 有什么方法可以预测客户端的网络是否支持 WebRTC 对等连接?
- django-models - 外键返回对象而不是整数
- css - 添加一个按钮以使用 ngAfterViewInit 更新 mat 表搜索
- r - 如何获取多个 Sample() 向量输出并将它们组合成一个数据框
- javascript - 错误 er_con_count_error 连接数过多表示 mysql
- api - 使用 Django REST 框架序列化 MPTT 树
- ios - Swift 回到根视图控制器
- php - 如何将传单多边形框放大 5%?
- python-3.x - 取最近的日期和最远的日期,并使用 .groupby 计算它们之间的月份