WordPress recent posts with content limit


<?php $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 2 ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID )); ?>
<div class=”col2″>
<div class=”article”>
<div class=”image”>
<a href=”<?php echo get_permalink($post->ID); ?>”>
<img src=”<?php echo $image ?>”>
</a>
</div>
<h2><a href=”<?php echo get_permalink($post->ID); ?>”><?php echo get_the_title(); ?></a></h2>
<p><?php $content = get_the_content(); echo mb_strimwidth($content, 0, 200, ‘…’);?></p>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s