Advertisement
Dannci

blog shortcode

Apr 14th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. Shortcode to display 'Design' category:
  2.  
  3. [loop category=design posts_number="6"]
  4.  
  5.  
  6. -------
  7.  
  8.  
  9. //php code (add into functions.php)
  10.  
  11.  
  12. function myLoop($atts, $content = null) {
  13. extract(shortcode_atts(array(
  14. "pagination" => 'true',
  15. "query" => '',
  16. "category" => '',
  17. "posts_number" => '',
  18. ), $atts));
  19. global $wp_query,$paged,$post;
  20. $temp = $wp_query;
  21. $wp_query= null;
  22. $wp_query = new WP_Query();
  23. if(!empty($category)){
  24. $query .= 'meta_key=post_views_count&orderby=date&category_name='.$category.'&showposts='.$posts_number;
  25. }
  26. if(!empty($query)){
  27. $query .= $query;
  28. }
  29. $wp_query->query($query);
  30. ob_start();
  31. ?>
  32. <ul class="loop">
  33. <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
  34. <li id="post-<?php the_ID(); ?>" class="threecol item_full body3">
  35. <?php get_template_part('/includes/post-types/blog-classic'); ?>
  36. </li>
  37. <?php endwhile; ?>
  38. </ul>
  39. <?php $wp_query = null; $wp_query = $temp;
  40. $content = ob_get_contents();
  41. ob_end_clean();
  42. return $content;
  43. }
  44. add_shortcode("loop", "myLoop");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement