Display post by category id
<?php
query_posts('cat=2&showposts=10');//put your category id in equal to cat
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="timeline">
<h3><?php the_title(); ?></h3>
<?php the_content();?>
<?php endwhile; else: ?>
<?php _e('No Posts Sorry.'); ?>
<?php endif; ?>
</div>
or with pagination we can use:
<?php
$the_query = new WP_Query( array('posts_per_page'=>9,
'post_type'=>'Post',
//'cat' => '12',
'order'=>'DESC',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1)
);
?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post();
?>
<a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail( $post_id, 'large' ); ?></a>
<a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a>
<?php the_excerpt(); ?>
<?php the_date(); ?><?php the_author(); ?>
<a href="<?php comments_link(); ?>">Leave a Comment</a>
<?php
endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
wp_reset_postdata();
?>
Comments
Post a Comment