Skip to:
Content
Pages
Categories
Search
Top
Bottom

Excluding certain blogs from bp_has_blogs() function for 1.2

  • Avatar of blgdra
    blgdra
    Participant

    @blogadera

    We have been trying to exclude certain blogs from our MU2.9.1/BP1.2 setup where we have used several sub-blogs as extensions of the main blog more like sections. Basically worked as a CMS. So we need to exclude these ‘blogs’ from the directory listings and any other instances, default or custom.

    bp_has_blogs(bp_query_string(‘blogs’)) for the directory instance

    bp_has_blogs() for some others and any custom

    we’ve been trying the available arg and tried bp_has_blogs(‘type=active&something) && !bp_has_blogs(‘user_id=1′) but doesn’t work and the reverse bp_has_blogs(‘user_id=1′) does work if I only wanted to show just user_id 1 blogs. don’t quite need that.

    we also tried listing, bp_has_blogs(‘user_id=1, 3,4′) and that doesn’t work fully for some reason. Don’t want to do that anyway since its not very practical.

    So any suggestions on what does work? would be great if we could exclude the user_id with bp_has_blogs(exclude=1) or even exclude blog_ids with bp_has_blogs(exclude=1,4,5).

    *Imagine the same idea to exclude would be helpful for has_members to exclude admin member and test profiles if needed…but we’ll carry that over to a new thread so we can focus on excluding admin blogs here.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Here’s what I’m using in the interim.

    Copy over /bp-default/blogs/blogs-loop.php to your child theme.

    Modify the while line so it looks like:

    <?php while ( bp_blogs() ) : bp_the_blog(); if(bp_get_blog_name() != "BLOG NAME YOU WANT TO EXCLUDE") : ?>

    You’ll also have to modify the blog count and pagination count so it reflects the number of blogs.

    You can do this by applying a filter to bp_get_total_blog_count. For the pagination count, you’ll need to duplicate the function and replace the existing one.

    It’s not the best solution, but it gets the job done for now.

    An “exclude” parameter, like you noted above, would be ideal.

    Avatar of blgdra
    blgdra
    Participant

    @blogadera

    Cool. Got it to work with the main blog, I guess now the obvious question from us would be how to exclude multiple blog names?

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Add to the “if” conditional.

    <?php while ( bp_blogs() ) : bp_the_blog(); if(bp_get_blog_name() != "BLOG NAME YOU WANT TO EXCLUDE" && bp_get_blog_name() != "SECOND BLOG NAME TO EXCLUDE") : ?>

    If you have a ton of blogs, you might want to use an array.

    Avatar of blgdra
    blgdra
    Participant

    @blogadera

    ok it worked. thanks r-a-y . this will work for now as you said. hope they work in that parameter soon.

    Avatar of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    I submitted a trac ticket http://trac.buddypress.org/ticket/2099 that will allow you to filter the output of bp_has_blogs. Once that goes in, it’ll make this sort of thing a bit less hacky – you can actually set up an exclude array in a plugin, and filter the blog list accordingly.

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    Boone, you are my hero! :)

    @blogadera – I modified the code snippet above because I made a typo, try again please.

    Avatar of Kunal17
    Kunal17
    Participant

    @kunal17

    Thanks, I needed this too.

    Since we are on the topic of excluding blogs, is there a way to exclude blogs that have only 1-2 posts? I have several members adding a new blog and posting once of twice and then never again and I would rather not have these clutter the blog directory.

    Thanks.

    Avatar of Windhamdavid
    Windhamdavid
    Participant

    @windhamdavid

    @Boone ~ Big thank U.. I tested the .diff this morning and let’s just say.. it’s much much less ‘hacky’ than what I had going on!

    Avatar of Marcus
    Marcus
    Participant

    @netweblogic

    Yeah, I’d like to see what Kunal17 asks for too. If nobody has a something out there yet I’ll probably end up making a plugin, especially to stop the blogs with only the first default post showing up.

Viewing 9 replies - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.