Advertisement
Guest User

Functions PHP

a guest
Mar 4th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /* Adds Schema Event Posts to Gardening Classes Page */
  2. function wpb_postsbycategory() {
  3. /* the query */
  4. $the_query = new WP_Query( array( 'post_type' => 'schema_event_post', 'posts_per_page' => 8 ) );
  5.  
  6. /* The Loop */
  7. if ( $the_query->have_posts() ) {
  8. $string .= '<ul class="postsbycategory widget_recent_entries">';
  9. while ( $the_query->have_posts() ) {
  10. $the_query->the_post();
  11. if ( has_post_thumbnail() ) {
  12. $string .= '<li>';
  13. $string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 150, 150) ) . get_the_title() .'</a><br /> '. get_the_excerpt() .'</li><br />';
  14. } else {
  15. /* if no featured image is found */
  16. $string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a><br /> '. get_the_excerpt() .'</li><br />';
  17. }
  18. }
  19. } else {
  20. /* no posts found */
  21. }
  22. $string .= '</ul>';
  23.  
  24. return $string;
  25.  
  26. /* Restore original Post Data */
  27. wp_reset_postdata();
  28. }
  29. /* Add a shortcode */
  30. add_shortcode('categoryposts', 'wpb_postsbycategory');
  31.  
  32. /* Enable shortcodes in text widgets */
  33. add_filter('widget_text', 'do_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement