Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode( 'rwcrnhome', 'rwcrn_home' );
- function rwcrn_home () {
- $output = '';
- $rwcrn_posts = get_posts( array(
- 'category_name' => 'news',
- 'numberposts' => 40,
- 'orderby' => 'post_date',
- 'order' => 'DESC'
- )
- );
- foreach ( $rwcrn_posts as $rwcrn_post ) {
- $images = get_children( array(
- 'post_parent' => $rwcrn_post->ID,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => 'ASC',
- 'orderby' => 'menu_order ID'
- )
- );
- foreach ( $images as $image ) {
- // Thumbnail
- $output .= wp_get_attachment_image( $image->ID, 'thumbnail', FALSE, array( 'align' => 'left', 'style' => 'padding-right: 10px' ) );
- break;
- };
- $output .= '<a href="';
- $output .= get_permalink( $rwcrn_post->ID );
- $output .= '">';
- $output .= get_the_title( $rwcrn_post->ID );
- $output .= "</a><br /><i>";
- $output .= get_the_time( get_option('date_format'), $rwcrn_post->ID );
- $output .= '<span class="sep"> by </span> <span class="author vcard">';
- $comments_count = wp_count_comments( $rwcrn_post->ID );
- setup_postdata( $rwcrn_post );
- $output .= get_the_author();
- $output .= '</span></i><br />';
- $output .= get_the_excerpt();
- wp_reset_postdata();
- if ( $comments_count->approved > 0 ) {
- $last_comment = get_comments( array( 'page_id' => $rwcrn_post->ID, 'number' => '1', 'orderby' => 'comment_date_gmt', 'order' => 'DESC' ) );
- $current_time_gmt = time() - date('Z');
- foreach ( $last_comment as $comment ) {
- if ( $comments_count->approved == 1 ) {
- $output .= '<br /><span style="color: rgb(0, 0, 255);">Comment ' . round( ( $current_time_gmt - strtotime( $comment->comment_date_gmt ) ) / 3600, 1 ) . ' hr. ago</span>';
- } else {
- $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>';
- }
- }
- }
- $output .= '<br clear="all" /><img src="http://rwcrn.com/wp/wp-content/uploads/2011/10/1px.png" width="100%" height="3">';
- wp_reset_postdata();
- }
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement