Skip to:
Content
Pages
Categories
Search
Top
Bottom

Template Tags Suggestion

  • I have a suggestion for many of the template tags functions, which will probably save people a heck of a lot of time when tweaking/creating themes.

    I found that when making my own theme, a huge issue is the functions that give the list of options, header tabs, etc. only offer a certain format, usually lists. These functions generate the lists themselves.

    My suggestion is that these functions call another function that supplies an array of the items which then turns it into an unordered list. That way we can call that function and do whatever we want with the links (filter, different structure, etc.).

    I’ve made a few for myself already (would be happy to forward them for inclusion), but here’s an example of what I did for the bp_groups_header_tabs(). The original function could grab this array and make the list fairly easily.

    (Sorry, when I use the code markup it doesn’t format it very well)

    <br />
    function bp_get_groups_header_tabs() {
    global $bp, $create_group_step, $completed_to_step;
    $array = array(
    'recently-active' => array( 'text' => __( 'Recently Active', 'buddypress' ) ),
    'recently-joined' => array( 'text' => __( 'Recently Joined', 'buddypress' ) ),
    'most-popular' => array( 'text' => __( 'Most Popular', 'buddypress' ) ),
    'admin-of' => array( 'text' => __( 'Administrator Of', 'buddypress' ) ),
    'mod-of' => array( 'text' => __( 'Moderator Of', 'buddypress' ) ),
    'alphabetically' => array( 'text' => __( 'Alphabetically', 'buddypress' ) )
    );
    //Add links and current check dynamically, takes up less space this way.
    foreach($array as $key => $value){
    $array[$key]['link'] = $bp->displayed_user->domain . $bp->groups->slug . '/my-groups/' . $key;
    $array[$key]['is_current'] = ( $key == $bp->action_variables[0] );
    }
    return $array;
    }

Viewing 1 replies (of 1 total)
  • In case someone is interested, you can then use the following function for any of these types of functions to make a select ddm which takes you to the right url when selected:

    function mrn_header_tabs($type){
    $tabs = call_user_func("bp_get_{$type}_header_tabs");
    ?>
    <select onchange="window.location = this.value;">
    <?php foreach($tabs as $tab) : ?>
    <option <?php if ( $tab['is_current'] ) : ?> selected="selected"<?php endif; ?> value="<?php echo $tab['link'] ?>/"><?php echo $tab['text'] ?></option>
    <?php endforeach; ?>
    </select>
    <?php
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Template Tags Suggestion’ is closed to new replies.
Skip to toolbar