I am new with word press and I want to show the post of a specific category on my page. The name of the category which i want to show is home slider
. Below is the code which I have used to display all the posts title
, image
and 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>
Can please anyone edit this code so that I can show posts of the specific category which in my case is home slider
.
Thank you.
category_name
and pass the slug of the category. There is no parameter that accepts the name of a term. If you only have the name, useget_term_by()
to get the complete category object, and from there get the ID and pass it tocategory
– Pieter Goosen Jul 1 '16 at 7:04