Advertisement
imranmodel32

short code function

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