Modding the blogs page

On the blogs page, that lists all the blogs, I want to modify the query that generates the list, I have the template in a child theme.

Here is the code on the page template that lists the blogs:

<div class="item-list-tabs" id="subnav" role="navigation">

    <?php do_action( 'bp_blogs_directory_blog_sub_types' ); ?>

    <li id="blogs-order-select" class="last filter">

    <label for="blogs-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    <select id="blogs-order-by">
    <option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option>
    <option value="newest"><?php _e( 'Newest', 'buddypress' ); ?></option>
    <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>

    <?php do_action( 'bp_blogs_directory_order_options' ); ?>

    </select>

</div>

(I hope that pasted ok)

Now where the active,newest, and alphabetical are, I would like to add "oldest", and by "userid" or "Username".

How can this be done? :slight_smile:
Please help, I've worked very hard on this...

  • ThePath

    Hi Jason, thanks for being a member and your forum post.

    You can add whatever you like to that block of code but it wont add any functionality I dont think. As these are just options in a dropdown.

    So you could have:

    <select id="blogs-order-by">
     <option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option>
     <option value="newest"><?php _e( 'Newest', 'buddypress' ); ?></option>
     <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
     <option value="oldest"><?php _e( 'Oldest', 'buddypress' ); ?></option>
     <option value="userid"><?php _e( 'UserID', 'buddypress' ); ?></option>
     <option value="username"><?php _e( 'Username', 'buddypress' ); ?></option>

    Sure it will add the options to the dropdown but how does it know what to do?

    Im not sure but there is probably some functions linked to these options via:

    <?php do_action( 'bp_blogs_directory_order_options' ); ?>

    Prob linked in to ajax too. But perhaps a more codey person can help, plus its late and Im sweepy :wink:

  • aecnu

    Greetings Jason,

    Thank you for this great question but I do not know the answer and we do not have a Buddy press specific developer to assign this ticket to and obviously this is a custom coding job.

    The Path is right that it will take more then just a menu adjustment.

    Rather then send you off to the jobs board or something to that effect I will let this ticket float a bit to see if someone in this great community will indeed offer up some coding expertise for you.

    Cheers, Joe

  • ThePath

    OK well Im not a coder but I might be able to help you with the oldest option.

    in the folder open file: plugins/buddypress/bp-blogs/bp-blogs-classes.php

    On line 89 you will see:

    switch ( $type ) {
    			case 'active': default:
    				$order_sql = "ORDER BY bm.meta_value DESC";
    				break;
    			case 'alphabetical':
    				$order_sql = "ORDER BY bm2.meta_value ASC";
    				break;
    			case 'newest':
    				$order_sql = "ORDER BY wb.registered DESC";
    				break;
    			case 'random':
    				$order_sql = "ORDER BY RAND()";
    				break;
    		}

    Change this too:

    switch ( $type ) {
    			case 'active': default:
    				$order_sql = "ORDER BY bm.meta_value DESC";
    				break;
    			case 'alphabetical':
    				$order_sql = "ORDER BY bm2.meta_value ASC";
    				break;
    			case 'newest':
    				$order_sql = "ORDER BY wb.registered DESC";
    				break;
    			case 'oldest':
    				$order_sql = "ORDER BY wb.registered ASC";
    				break;
    			case 'random':
    				$order_sql = "ORDER BY RAND()";
    				break;
    		}

    and remember to add the "oldest" item to the dropdown:

    <select id="blogs-order-by">
     <option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option>
     <option value="newest"><?php _e( 'Newest', 'buddypress' ); ?></option>
     <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
     <option value="oldest"><?php _e( 'Oldest', 'buddypress' ); ?></option>

    Does that work? Let me know.

    To get your username/userid filter to work would require a lot more work and an extra field where you would insert the name/id. However I was thinking doesnt buddypress kinda have this already with the standard search bar in the header with the dropdown containing members, groups, blogs, posts.......couldnt you search via username using the "blogs" search?

    Hope that helps ya dude.

  • Jason

    Yes, Thanks @ThePath, that's a tremendous help. I know enough php and html that just changing the html wouldn't do anything, I didn't even try. I'll be honest, I'm actually trying to filter blogs by a custom post type taxonomy as well, and I just needed some direction. I tried three different ways until I realized this would be easiest if I could just talk to someone about it.

    I would like to avoid BP Core hacking if at all possible, I was hoping I could replace the query all together using a bp action, filter or hook.

    Maybe I can extend the BuddyPress blog class and replace the function with my own in a bp-custom.php, that way my customization will survive an update?

    I'm not a big fan of buddypress, it's got a bit of a learning curve, but it has some really great features that I want to build on. I wish the documentation out there was a bit better though.

    @Joe
    I'm surprised there's not a Buddypress guru around here with all the BP themes and plugins around here that support buddypress!

  • aecnu

    Greetings Jason,

    I'm surprised there's not a Buddypress guru around here with all the BP themes and plugins around here that support buddypress!

    I hear you on that!

    The theme developers that developed those themes are no longer with us.

    Regarding the plugins for the mass majority of them I am thinking they could be coded as WordPress and just test if they still work in Buddy press and if so there you have it.

    I would imagine that the majority of Buddy Press guru's and coders are over on the Buddy press site though I admit I wish we had some of our own or someone designated to handle Buddy press issues.

    Thank you for your input there Jason, it is indeed appreciated.

    Cheers, Joe

  • Jason

    Just a heads up then, when the new version of buddypress 1.7 comes out, it's going to become very popular. They're really pulling together and the new release will no longer be theme dependent. They are working with the wordpress team on tighter integration and a much smaller footprint. It's really exciting actually cause buddypress has always been such a mess.

    Right now, I do need to ask a developer a question though. I'm trying to override a function in a parent class. How can I do that? I know how to extend a class. But I need to overwrite a function while the parent class is still the class being called.

    I hope that makes sense, here, in other words:

    I want to replace the "GET" function in http://svn.buddypress.org/trunk/bp-blogs/bp-blogs-classes.php

    With my own without hacking the core files.

  • aecnu

    Greetings Jason,

    Thank you for your additional input here, as you well know by now it is greatly appreciated helping to clarify issues and perspectives.

    I do not have anything more at this point to offer to this ticket then the immediately above comment but also I want to keep this ticket from falling into the ticket system abyss as I await to see if anyone anywhere has a solution for your query.

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.