Skip to content

Instantly share code, notes, and snippets.

@sumanahmed
Created January 8, 2016 06:26
Show Gist options
  • Save sumanahmed/b5aaf992cc756b4a6b9a to your computer and use it in GitHub Desktop.
Save sumanahmed/b5aaf992cc756b4a6b9a to your computer and use it in GitHub Desktop.
function category_post_shortcode($atts){
extract( shortcode_atts( array(
'title' => '',
'link' => '',
'category' => '',
), $atts, 'category_post' ) );
global $post;
$q = new WP_Query(
array( 'category' => $category, 'posts_per_page' => '3', 'post_type' => 'post')
);
$list = '<div class="latest_from_category"><h2 class="latest_frm_cat_title">'.$title.'</h2> <a href="'.$link.'" class="latest_more_link">more</a>';
while($q->have_posts()) : $q->the_post();
//get the ID of your post in the loop
$id = get_the_ID();
$post_excerpt = get_post_meta($id, 'post_excerpt', true);
$post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
$list .= '
<div class="single_cate_post floatleft">
'.$post_thumbnail.'
<h3>'.get_the_title().'</h3>
<p>'.$post_excerpt.'</p>
<a href="'.get_permalink().'" class="readmore">Read More</a>
</div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('category_post', 'category_post_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment