Skip to:
Content
Pages
Categories
Search
Top
Bottom

HELP: Adjust Recent Blog Widget for 2 Categories Only

  • @anonymized-303747

    Inactive

    Hi,

    I’m messing with BuddyPress and I am running out of ideas.

    Basically, I’m trying to limit the display if posts in the Recent Blog Posts Widget to 1 blog_id and 2 categories or to 2 blog_ID’s. Either way works for me but I’d be interested in both scenarios. In a regular WP loop, this would be easy to do but man, this widget business is a whole different matter for me.

    Can anyone please provide some pointers? I have a feeling it’s dead simple (if you know how, isn’t that always the case) – but I’m getting stuck.

    TIA

Viewing 15 replies - 1 through 15 (of 15 total)
  • @gerbilo

    Participant

    i guess function get_latest_posts in bp-blogs/bp-blogs-classes.php should help you to do this. Ofcourse this is a brutal way.. )

    @anonymized-303747

    Inactive

    In times of desperation, the brutal way trumps anything else :)

    function get_latest_posts( $blog_id = null, $limit = 5 ) {
    global $wpdb, $bp;

    if ( $blog_id )
    $blog_sql = $wpdb->prepare( " AND p.blog_id = %d", $blog_id );

    $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM " . $bp['blogs']['table_name_blog_posts'] . " p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 $blog_sql ORDER BY p.date_created DESC LIMIT $limit" ) );

    for ( $i = 0; $i < count($post_ids); $i++ ) {
    $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
    }

    return $posts;
    }

    That’s the function. What would need adjustment here?

    @gerbilo

    Participant

    $blog_sql = $wpdb->prepare( ” AND p.blog_id = 1″, $blog_id );

    for example. for main blog – try it )

    @anonymized-303747

    Inactive

    That actually doesn’t work for me – does this do the job for you?

    @gerbilo

    Participant

    so play with it! i have only one blog, so i can’t test it!

    change for example:

    LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = 1 WHERE

    @anonymized-303747

    Inactive

    Ah – that does limit the output to blog_id=1 but lists posts multiple times, as in:

    Blog_ID=1:

    Post 2

    Post 2

    Post 2

    Post 1

    Post 1

    By the way, reason for this modification is that I am running an aggregator, which records post headlines to a dedicated blog. Without limiting the output in the recent blog posts widget, the widget is overrun with RSS headlines. A similar need would exist for people that want to give individuals blogs, but want to control that only ‘self-owned” or moderated blogs push content directly to the front page. Someone else stated that requirement in another thread.

    @gerbilo

    Participant

    ofcourse id does. you must write SELECT DISTINCT p.post_id..

    @anonymized-303747

    Inactive

    Argh – haven’t had my coffee yet. This works like a champ. One last question while I’m on this topic:

    What if I would want to list posts from two blogs (ie blog_id=1 and blog_id=2) – how would the code below look?

    LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = 1 WHERE..

    @gerbilo

    Participant

    LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id IN (1,2) WHERE...

    something like that i guess..

    @anonymized-303747

    Inactive

    gerbilo, I owe you one. Perfect!

    In summary – objective was to limit the output in the Recent Blog Posts widget to only a few selected (in my case self-owned) blogs.

    Edit bp-blogs-classes.php:

    Replace:

    $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM " . $bp['blogs']['table_name_blog_posts'] . " p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 $blog_sql ORDER BY p.date_created DESC LIMIT $limit" ) );

    With

    $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT p.post_id, p.blog_id FROM " . $bp['blogs']['table_name_blog_posts'] . " p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id IN (1,2) WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 $blog_sql ORDER BY p.date_created DESC LIMIT $limit" ) );

    In my example, I use blog_id 1 and blog_id 2.

    I don’t like hacking the code, so if there’s anyone who knows to get this done by putting it in the mu-plugins directory and leave the BP code untouched, I’d be interested in learning about it.

    Thanks again, gerbilo!

    @gerbilo

    Participant

    np jvinch, brutal force is my power )) next step will be learning to write plugins, so core files will stay untouched after my ‘work’ )))

    @burtadsit

    Participant

    @jvinch

    This is about the trac ticket you posted. Can’t register again with same email address after deleting user. I’m just hunting you down since you might not read the comments on the ticket.

    That is a side effect of mu storing the users in wp_signups table and not getting rid of them from there when deleting a user. Don’t ask me why, it just does. If you want to re-use that email address you have to kill the appropriate rec in wp_signups.

    @anonymized-303747

    Inactive

    Thanks burtadsit -I actually do check trac recently for comments but thanks for the clarification anyway.

    @gerbilo

    Participant

    burtadsit.. br.. that’s bad.. so we need to edit DELETE function, to add wp_signups in it )

    @burtadsit

    Participant

    I don’t know what the purpose of leaving it there is. Gotta be a reason. You might ask over at the mu forums. Perhaps it gets removed after a period of time? As a site admin I don’t want people signing up getting deleted by me and then signing up again? Dunno.

    This is off topic for this thread. Sorry.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘HELP: Adjust Recent Blog Widget for 2 Categories Only’ is closed to new replies.
Skip to toolbar