我是word press的新手,我想在我的页面上显示特定类别的帖子。我要显示的类别的名称为home slider
. 下面是我用来显示所有帖子的代码title
, image
和content
.
<div class="row">
<?php $myposts = get_posts( \'numberposts=6&offset=$debut\' );
foreach( $myposts as $post) : setup_postdata( $post ) ?>
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<?php the_post_thumbnail( \'thumbnail\'); ?>
<div class="caption">
<h4 class="pull-right">$94.99</h4>
<a> <?php the_title(); ?> </a>
<!--I have used this substr here to set the limit of the text, and if do not want to set the limit simply use this line of code <?php //the_content(); ?>-->
<?php echo substr(get_the_excerpt(), 0,30); ?>...
<a href="#" >read more</a>
</div>
<div class="ratings">
<p class="pull-right">18 reviews</p>
<p>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star"></span>
<span class="glyphicon glyphicon-star-empty"></span>
</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
可以请任何人编辑此代码,以便我可以显示特定类别的帖子,在我的情况下是
home slider
.非常感谢。
最合适的回答,由SO网友:Rajpreet 整理而成
改变$myposts = get_posts( \'numberposts=6&offset=$debut\')
到$myposts = get_posts( \'numberposts=6&category_name=home-slider&offset=$debut\')
或$myposts = get_posts( \'numberposts=6&category=1&offset=$debut\')
用类别ID替换1
希望这有帮助