Advertisement
Guest User

Untitled

a guest
May 25th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // Homepage featured posts shortcode
  2. // Usage: [homepage_featured_posts] or [homepage_featured_posts posts_per_page="4" size="home-middle" offset="1"]
  3. add_shortcode( 'homepage_featured_posts', 'homepage_featured_posts' );
  4. function homepage_featured_posts($atts) {
  5.  
  6. // Attributes
  7. $atts = shortcode_atts(
  8. array(
  9. 'posts_per_page' => '1', // the default number
  10. 'offset' => '0',
  11. 'size' => 'home-top',
  12. ),
  13. $atts, 'homepage_featured_posts'
  14. );
  15.  
  16.  
  17. // WP_Query arguments
  18. $args = array(
  19. 'post_type' => 'post',
  20. 'posts_per_page' => $atts['posts_per_page'],
  21. 'offset' => $atts['offset'],
  22. );
  23.  
  24. // The Query
  25. $query = new WP_Query( $args );
  26.  
  27. // Set up the featured content div before the loop
  28. $buffer = '<div class="featured-content">';
  29.  
  30. // The Loop
  31. if ( $query->have_posts() ) {
  32. while ( $query->have_posts() ) {
  33. $query->the_post();
  34.  
  35. $size = $atts['size'];
  36.  
  37. $img = genesis_get_image( array(
  38. 'format' => 'html',
  39. 'size' => $size,
  40. 'attr' => genesis_parse_attr( $size, array ( 'alt' => '') ),
  41. ) );
  42.  
  43. $buffer .= '<article class="entry featured-post">';
  44. $buffer .= '<a class="aligncenter" href="'.get_permalink().'">';
  45. $buffer .= $img;
  46. $buffer .= '<h4 class="entry-title" itemprop="headline">'. get_the_title().'</h4></a>';
  47. $buffer .= '<p><time class="entry-time" itemprop="datePublished" datetime="'.get_the_date( 'c' ).'">'. get_the_date(). '</time></p>';
  48. $buffer .= '<div class="entry-content"><p>'. get_the_excerpt(). '</p></div>';
  49. $buffer .= '</article>';
  50.  
  51. } // end of while loop
  52. } // end of if statement
  53. else {
  54. // no posts found, do nothing
  55. } // end of else statement
  56.  
  57. // close the featured content div out of the loop
  58. $buffer .= '</div>'; // close the featured-content div
  59.  
  60. // Restore original Post Data
  61. wp_reset_postdata();
  62. return $buffer;
  63. } // end of function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement