Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/01/2012 08:20:19 PM (12 years ago)
Author:
djpaul
Message:

Extend the functionality of the latest post tracking in the Blogs component by creating template functions for a post's title and content, as well as fetching any post thumbnail. Fixes #4570

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-classes.php

    r6342 r6372  
    262262        for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
    263263            $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
    264             $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
     264            $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT ID, post_content, post_title, post_excerpt, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
     265            $images = array();
     266
     267            // Add URLs to any Featured Image this post might have
     268            if ( has_post_thumbnail( $paged_blogs[$i]->latest_post->ID ) ) {
     269
     270                // Grab 4 sizes of the image. Thumbnail.
     271                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'thumbnail', false );
     272                if ( ! empty( $image ) )
     273                    $images['thumbnail'] = $image[0];
     274
     275                // Medium
     276                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'medium', false );
     277                if ( ! empty( $image ) )
     278                    $images['medium'] = $image[0];
     279
     280                // Large
     281                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'large', false );
     282                if ( ! empty( $image ) )
     283                    $images['large'] = $image[0];
     284
     285                // Post thumbnail
     286                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'post-thumbnail', false );
     287                if ( ! empty( $image ) )
     288                    $images['post-thumbnail'] = $image[0];
     289            }
     290
     291            // Add the images to the latest_post object
     292            $paged_blogs[$i]->latest_post->images = $images;
    265293        }
    266294
Note: See TracChangeset for help on using the changeset viewer.