Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add excerpt and post thumbnail to Buddypress blog directory page WordPress

Hi

I am trying to display excerpt and thumbnail for the posts shown in the buddypress blog directory page. By default only avatar thumb and title link to the posts are shown.

I have created a function based on the function bp_blog_latest_post() used in the blogs loop but I am not sure how to proceed. I can see that the blog template class is accessed but don't know how to access further information, if this is not possible then do I need to use the buddypress excerpt filter as well? Here is the slightly customised function so far..

<?php

function bp_blog_latest_post_excerpt() {
echo bp_get_blog_latest_post_excerpt();
}

function bp_get_blog_latest_post_excerpt() {

//global variable carying data used in blog templae
global $blogs_template;
//if no posts then return nothing (and default to message I assume)
if (null == $blogs_template->blog->latest_post)
return false;
//otherwise..
return apply_filters( 'bp_get_blog_latest_post', apply_filters( 'the_excerpt', $blogs_template->blog->latest_post->post_excerpt) );
}
?>


Thanks in advance.

Answers (2)

2012-09-06

Arnav Joy answers:

ARE YOU GETTING ANY OUTPUT FROM ABOVE FUNCTION?


Paul Featherstone comments:

Nothing unfortunately, see here:

http://ebookforum.info/members/blogs/

After 'excerpt'.

2012-09-06

Dbranes answers:

i don't think you can use

$blogs_template->blog->latest_post->post_excerpt


by digging into the core bp code it looks like the

$blogs_template->blog->latest_post

only has 2 fields: 'post_titles' and 'guid' ;-)


update: I think this is the line in <strong>bp-blogs-classes.php</strong> that responsible for the structure of <strong>latest_post</strong>:

$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" );


Paul Featherstone comments:

That's right, as per the standard template use (not sure what 'guid' comes from though?? or am I missing something).

I put the example up as a demonstration of what I was trying to achieve if there had of been.

Looks like I might have to access 'latest_post' and then filter using 'the_excerpt' - is this possible. Think it should be just not sure on the syntax.

I looked at the sidewide activity widget as this does what I want..didn't look straight forward hmm..


Dbranes comments:

ok, if we could some how put <strong>post_excerpt</strong> into the last_post query, i.e.

"SELECT post_title, guid, post_excerpt FROM ..."


we might get the results you are looking for.

One idea would be to use the <strong>bp_blogs_get_blogs</strong> filter from

http://svn.buddypress.org/trunk/bp-blogs/bp-blogs-functions.php

as a starting point and then use a slightly different functions instead of <strong>BP_Blogs_Blog::get</strong> and BP_Blogs_Blog::get_blog_extras.

that's just an idea ;-)


Dbranes comments:

ps: as a quick fix, you could try using a function like this:

function my_get_latest_blog_post( $blog_id) {
global $wpdb;
$post = $wpdb->get_row('SELECT * FROM ' . $wpdb->get_blog_prefix( $blog_id ) . 'posts where post_status="publish" and post_type="post" order by post_date desc limit 0,1 ' );
return $post
}

so you can directly fetch the latest post inside the bp loop:

<?php while ( bp_blogs() ) : bp_the_blog(); ?>
...
<?php
global $blogs_template;
$p=my_get_latest_blog_post($blogs_template->blog->blog_id);
//print_r($p);
echo $p->post_title;
echo $p->post_date;
echo $p->post_content; // you could then make an excerpt from this
?>
...
<?php endwhile; ?>