Advertisement
imranmodel32

category post qurey by shortcode

Nov 11th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. function category_post_shortcode($atts){
  2. extract( shortcode_atts( array(
  3. 'title' => '',
  4. 'link' => '',
  5. 'category' => '',
  6. ), $atts, 'category_post' ) );
  7.  
  8. $q = new WP_Query(
  9. array( 'category' => $category, 'posts_per_page' => '3', 'post_type' => 'post')
  10. );
  11. $list = '<div class="latest_from_category"><h2 class="latest_frm_cat_title">'.$title.'</h2> <a href="'.$link.'" class="latest_more_link">more</a>';
  12.  
  13. while($q->have_posts()) : $q->the_post();
  14. //get the ID of your post in the loop
  15. $id = get_the_ID();
  16.  
  17. $post_excerpt = get_post_meta($id, 'post_excerpt', true);
  18. $post_thumbnail= get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
  19. $list .= '
  20.  
  21. <div class="single_cate_post floatleft">
  22. '.$post_thumbnail.'
  23. <h3>'.get_the_title().'</h3>
  24. <p>'.$post_excerpt.'</p>
  25. <a href="'.get_permalink().'" class="readmore">Read More</a>
  26. </div>
  27. ';
  28. endwhile;
  29. $list.= '</div>';
  30. wp_reset_query();
  31. return $list;
  32. }
  33. add_shortcode('category_post', 'category_post_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement