How to display post from a category in wordpress?
How to display post from a category in wordpress?
Simply copy and paste the code in your php file and change the category id which one you want to show.
<h4>Latest Post</h4>
<ul class="list-blog">
<?php
query_posts(array('category__in' => array(4),'posts_per_page' => 4));
while(have_posts()) { the_post();
?>
<li>
<?php
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
if($post_thumbnail_url!='')
{
$post_thumbnail_url = $post_thumbnail_url;
}else
{
$post_thumbnail_url = get_template_directory_uri().'/img/noimg.jpg';
}
?>
<img width="60" height="60" alt="" class="img-square" src="<?php echo $post_thumbnail_url;?>">
<div class="title">
<a href="<?=get_permalink($post->ID)?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a><br>
<span class="date time"><?php the_time(__ ('F j, Y')) ?></span>
</div>
</li>
<?php } wp_reset_postdata();?>
</ul>
<ul class="list-blog">
<?php
query_posts(array('category__in' => array(4),'posts_per_page' => 4));
while(have_posts()) { the_post();
?>
<li>
<?php
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
if($post_thumbnail_url!='')
{
$post_thumbnail_url = $post_thumbnail_url;
}else
{
$post_thumbnail_url = get_template_directory_uri().'/img/noimg.jpg';
}
?>
<img width="60" height="60" alt="" class="img-square" src="<?php echo $post_thumbnail_url;?>">
<div class="title">
<a href="<?=get_permalink($post->ID)?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a><br>
<span class="date time"><?php the_time(__ ('F j, Y')) ?></span>
</div>
</li>
<?php } wp_reset_postdata();?>
</ul>
Comments
Post a Comment