Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. // Get the posts query.
  2. $posts = rpwe_get_posts( $args );
  3.  
  4. if ( $posts->have_posts() ) :
  5.  
  6.  
  7.  
  8. while ( $posts->have_posts() ) : $posts->the_post();
  9. $html = '<article>';
  10. // Thumbnails
  11. $thumb_id = get_post_thumbnail_id(); // Get the featured image id.
  12. $img_url = wp_get_attachment_url( $thumb_id ); // Get img URL.
  13.  
  14. // Display the image url and crop using the resizer.
  15. $image = rpwe_resize( $img_url, $args['thumb_width'], $args['thumb_height'], true );
  16.  
  17. // Start recent posts markup.
  18. $html .= '<figure>';
  19.  
  20. if ( $args['date'] ) :
  21. $day = get_the_date('j');
  22. $month = get_the_date('M');
  23. $html .= '<div><strong>' . esc_html( $day ) . '</strong>' .esc_html( $month ) .'</div>';
  24. endif;
  25.  
  26. if ( $args['thumb'] ) :
  27.  
  28. // Check if post has post thumbnail.
  29. if ( has_post_thumbnail() ) :
  30. $html .= '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
  31. if ( $image ) :
  32. $html .= '<img src="' . esc_url( $image ) . '" alt="' . esc_attr( get_the_title() ) . '">';
  33. else :
  34. $html .= '<img src="' . esc_url( $img_url ) . '" alt="' . esc_attr( get_the_title() ) . '" height="' . $args['thumb_height'] . '" width="' . $args['thumb_width'] . '">';
  35. endif;
  36. $html .= '</a>';
  37.  
  38. // If no post thumbnail found, check if Get The Image plugin exist and display the image.
  39. elseif ( function_exists( 'get_the_image' ) ) :
  40. $html .= get_the_image( array(
  41. 'height' => (int) $args['thumb_height'],
  42. 'width' => (int) $args['thumb_width'],
  43. 'image_scan' => true,
  44. 'echo' => false,
  45. 'default_image' => esc_url( $args['thumb_default'] )
  46. ) );
  47.  
  48. // Display default image.
  49. elseif ( ! empty( $args['thumb_default'] ) ) :
  50. $html .= sprintf( '<a href="%1$s" rel="bookmark"><img src="%3$s" alt="%4$s" width="%5$s" height="%6$s"></a>',
  51. esc_url( get_permalink() ),
  52. esc_attr( $args['thumb_align'] ),
  53. esc_url( $args['thumb_default'] ),
  54. esc_attr( get_the_title() ),
  55. (int) $args['thumb_width'],
  56. (int) $args['thumb_height']
  57. );
  58.  
  59. endif;
  60.  
  61. endif;
  62. $html .= '</figure>';
  63. $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>';
  64.  
  65.  
  66.  
  67. if ( $args['excerpt'] ) :
  68. $html .= '<p>';
  69. $html .= wp_trim_words( apply_filters( 'rpwe_excerpt', get_the_excerpt() ), $args['length'], ' &hellip;' );
  70.  
  71. $html .= '</p>';
  72. if ( $args['readmore'] ) :
  73. $html .= '<a href="' . esc_url( get_permalink() ) . '" class="read-more">' . $args['readmore_text'] . '</a>';
  74. endif;
  75. endif;
  76.  
  77. $html .= '</article>';
  78.  
  79. endwhile;
  80.  
  81. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement