Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get the posts query.
- $posts = rpwe_get_posts( $args );
- if ( $posts->have_posts() ) :
- while ( $posts->have_posts() ) : $posts->the_post();
- $html = '<article>';
- // Thumbnails
- $thumb_id = get_post_thumbnail_id(); // Get the featured image id.
- $img_url = wp_get_attachment_url( $thumb_id ); // Get img URL.
- // Display the image url and crop using the resizer.
- $image = rpwe_resize( $img_url, $args['thumb_width'], $args['thumb_height'], true );
- // Start recent posts markup.
- $html .= '<figure>';
- if ( $args['date'] ) :
- $day = get_the_date('j');
- $month = get_the_date('M');
- $html .= '<div><strong>' . esc_html( $day ) . '</strong>' .esc_html( $month ) .'</div>';
- endif;
- if ( $args['thumb'] ) :
- // Check if post has post thumbnail.
- if ( has_post_thumbnail() ) :
- $html .= '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
- if ( $image ) :
- $html .= '<img src="' . esc_url( $image ) . '" alt="' . esc_attr( get_the_title() ) . '">';
- else :
- $html .= '<img src="' . esc_url( $img_url ) . '" alt="' . esc_attr( get_the_title() ) . '" height="' . $args['thumb_height'] . '" width="' . $args['thumb_width'] . '">';
- endif;
- $html .= '</a>';
- // If no post thumbnail found, check if Get The Image plugin exist and display the image.
- elseif ( function_exists( 'get_the_image' ) ) :
- $html .= get_the_image( array(
- 'height' => (int) $args['thumb_height'],
- 'width' => (int) $args['thumb_width'],
- 'image_scan' => true,
- 'echo' => false,
- 'default_image' => esc_url( $args['thumb_default'] )
- ) );
- // Display default image.
- elseif ( ! empty( $args['thumb_default'] ) ) :
- $html .= sprintf( '<a href="%1$s" rel="bookmark"><img src="%3$s" alt="%4$s" width="%5$s" height="%6$s"></a>',
- esc_url( get_permalink() ),
- esc_attr( $args['thumb_align'] ),
- esc_url( $args['thumb_default'] ),
- esc_attr( get_the_title() ),
- (int) $args['thumb_width'],
- (int) $args['thumb_height']
- );
- endif;
- endif;
- $html .= '</figure>';
- $html .= '<h1><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'rpwe' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">' . esc_attr( get_the_title() ) . '</a></h3>';
- if ( $args['excerpt'] ) :
- $html .= '<p>';
- $html .= wp_trim_words( apply_filters( 'rpwe_excerpt', get_the_excerpt() ), $args['length'], ' …' );
- $html .= '</p>';
- if ( $args['readmore'] ) :
- $html .= '<a href="' . esc_url( get_permalink() ) . '" class="read-more">' . $args['readmore_text'] . '</a>';
- endif;
- endif;
- $html .= '</article>';
- endwhile;
- endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement