Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2.  
  3. function post_list_shortcode($atts){
  4. extract( shortcode_atts( array(
  5. 'count' => '',
  6. ), $atts) );
  7.  
  8. $q = new WP_Query(
  9. array('posts_per_page' => $count, 'post_type' => 'posttype', 'orderby' => 'menu_order','order' => 'ASC')
  10. );
  11.  
  12. $list = '<div class="custom-post-list">';
  13. while($q->have_posts()) : $q->the_post();
  14. $idd = get_the_ID();
  15. $custom_field = get_post_meta($idd, 'custom_field', true);
  16. $post_content = get_the_content();
  17. $list .= '
  18. <div class="single-post-item">
  19. <h2>' .do_shortcode( get_the_title() ). '</h2>
  20. '.wpautop( $post_content ).'
  21. <p>'.$custom_field.'</p>
  22. </div>
  23. ';
  24. endwhile;
  25. $list.= '</div>';
  26. wp_reset_query();
  27. return $list;
  28. }
  29. add_shortcode('post_list', 'post_list_shortcode');
  30.  
  31.  
  32. function shortcode_with_attributes( $atts, $content = null ) {
  33.  
  34. extract( shortcode_atts( array(
  35. 'attribute' => '',
  36. 'another' => ''
  37. ), $atts ) );
  38.  
  39. return '
  40. <div class="shortcode-wrapper">
  41. <h2>'.$attribute.'</h2>
  42. '.$another.'
  43. </div>
  44. ';
  45. }
  46. add_shortcode('shortcode_name', 'shortcode_with_attributes');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement