我有一个名为“Blog”的定制帖子类型,其中包含一个归档模板-su_blog.php。在模板中,我只是调用标准循环来提取所有的帖子,然后使用一些html来构造页面。
我想知道是否有可能为最近的帖子更改html和样式?而不是对所有的人都有相同的html。我知道如何使用自定义查询来完成这个任务,但我很好奇是否有一种使用标准循环的方法?
我想用标准的if ( have_posts() ) : while ( have_posts() ) : the_post();循环做什么的例子。
<div class="featured-post">
<div class="col-sm-6 featured-img"><img src=""></div>
<div class="col-sm-6 featured-info"> </div>
</div>
<div class="default-post">
<div class="post-info"></div>
</div>谢谢
发布于 2017-11-15 15:16:11
// Query Arguments
$args = array(
'post_type' => array('blog'),
'order' => 'DESC',
'orderby' => 'date',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
$i = 0;
while ( $query->have_posts() ) {
if($i ==0){
// My Custom style
$query->the_post();
?>
<div class="featured-post">
<div class="col-sm-6 featured-img"><img src=""></div>
<div class="col-sm-6 featured-info"> </div>
</div>
<?php
// End of my Custom style
$i++;
}else{
$query->the_post();
?>
<div class="default-post">
<div class="post-info"></div>
</div>
<?php
}
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();https://stackoverflow.com/questions/47310808
复制相似问题