Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Homepage featured posts shortcode
- // Usage: [homepage_featured_posts] or [homepage_featured_posts posts_per_page="4" size="home-middle" offset="1"]
- add_shortcode( 'homepage_featured_posts', 'homepage_featured_posts' );
- function homepage_featured_posts($atts) {
- // Attributes
- $atts = shortcode_atts(
- array(
- 'posts_per_page' => '1', // the default number
- 'offset' => '0',
- 'size' => 'home-top',
- ),
- $atts, 'homepage_featured_posts'
- );
- // WP_Query arguments
- $args = array(
- 'post_type' => 'post',
- 'posts_per_page' => $atts['posts_per_page'],
- 'offset' => $atts['offset'],
- );
- // The Query
- $query = new WP_Query( $args );
- // Set up the featured content div before the loop
- $buffer = '<div class="featured-content">';
- // The Loop
- if ( $query->have_posts() ) {
- while ( $query->have_posts() ) {
- $query->the_post();
- $size = $atts['size'];
- $img = genesis_get_image( array(
- 'format' => 'html',
- 'size' => $size,
- 'attr' => genesis_parse_attr( $size, array ( 'alt' => '') ),
- ) );
- $buffer .= '<article class="entry featured-post">';
- $buffer .= '<a class="aligncenter" href="'.get_permalink().'">';
- $buffer .= $img;
- $buffer .= '<h4 class="entry-title" itemprop="headline">'. get_the_title().'</h4></a>';
- $buffer .= '<p><time class="entry-time" itemprop="datePublished" datetime="'.get_the_date( 'c' ).'">'. get_the_date(). '</time></p>';
- $buffer .= '<div class="entry-content"><p>'. get_the_excerpt(). '</p></div>';
- $buffer .= '</article>';
- } // end of while loop
- } // end of if statement
- else {
- // no posts found, do nothing
- } // end of else statement
- // close the featured content div out of the loop
- $buffer .= '</div>'; // close the featured-content div
- // Restore original Post Data
- wp_reset_postdata();
- return $buffer;
- } // end of function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement