Advertisement
jonradio

wp_count_comments issue

Jul 8th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.14 KB | None | 0 0
  1. add_shortcode( 'rwcrnhome', 'rwcrn_home' );
  2.  
  3. function rwcrn_home () {
  4.     $output = '';
  5.     $rwcrn_posts = get_posts( array(
  6.         'category_name' => 'news',
  7.         'numberposts'   => 40,
  8.         'orderby' => 'post_date',
  9.         'order' => 'DESC'
  10.         )
  11.     );
  12.  
  13.     foreach ( $rwcrn_posts as $rwcrn_post ) {
  14.         $images = get_children( array(
  15.             'post_parent' => $rwcrn_post->ID,
  16.             'post_status' => 'inherit',
  17.             'post_type' => 'attachment',
  18.             'post_mime_type' => 'image',
  19.             'order' => 'ASC',
  20.             'orderby' => 'menu_order ID'   
  21.             )
  22.         );
  23.         foreach ( $images as $image ) {
  24.             //  Thumbnail
  25.             $output .= wp_get_attachment_image( $image->ID, 'thumbnail', FALSE,  array( 'align' => 'left', 'style' => 'padding-right: 10px' ) );
  26.             break;
  27.         };
  28.         $output .= '<a href="';
  29.         $output .= get_permalink( $rwcrn_post->ID );
  30.         $output .= '">';
  31.         $output .= get_the_title( $rwcrn_post->ID );
  32.         $output .= "</a><br /><i>";
  33.         $output .= get_the_time( get_option('date_format'), $rwcrn_post->ID );
  34.         $output .= '<span class="sep"> by </span> <span class="author vcard">';
  35.         $comments_count = wp_count_comments( $rwcrn_post->ID );
  36.         setup_postdata( $rwcrn_post );
  37.         $output .= get_the_author();
  38.         $output .= '</span></i><br />';
  39.         $output .= get_the_excerpt();
  40.         wp_reset_postdata();
  41.         if ( $comments_count->approved > 0 ) {
  42.             $last_comment = get_comments( array( 'page_id' => $rwcrn_post->ID, 'number' => '1', 'orderby' => 'comment_date_gmt', 'order' => 'DESC' ) );
  43.             $current_time_gmt = time() - date('Z');
  44.             foreach ( $last_comment as $comment ) {
  45.                 if ( $comments_count->approved == 1 ) {
  46.                     $output .= '<br /><span style="color: rgb(0, 0, 255);">Comment ' . round( ( $current_time_gmt - strtotime( $comment->comment_date_gmt ) ) / 3600, 1 ) . ' hr. ago</span>';
  47.                 } else {
  48.                     $output .= '<br /><span style="color: rgb(0, 0, 255);">' . "Most Recent Comment (of $comments_count->approved) " . round( ( $current_time_gmt - strtotime( $comment->comment_date_gmt ) ) / 3600, 1 ) . ' hr. ago</span>';
  49.                 }
  50.             }
  51.         }
  52.         $output .= '<br clear="all" /><img src="http://rwcrn.com/wp/wp-content/uploads/2011/10/1px.png" width="100%" height="3">';
  53.         wp_reset_postdata();
  54.     }
  55.     return $output;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement