featured_forums
Coding

Feature Your Forums And Get Them Noticed!

The forums on our Buddypress sites are the heart and soul of our communities, but how do we get them noticed more by our visitors and how do we keep those visitors up to date with the latest that’s going on?

I’m going to give you 2 VERY SIMPLE tricks that will enhance the visibility of your forums as well as make them quicker and easier to access.

Trick 1 – Make your forums the default ‘Groups’ tab

This trick can be done in 2 minutes and merely requires you to paste the following code into your bp-custom.php file:

function redirect_to_forum() {
global $bp;
$path = clean_url( $_SERVER['REQUEST_URI'] );
$path = apply_filters( 'bp_uri', $path );
if ( bp_is_group_home() && strpos( $path, $bp->bp_options_nav['groups']['home']['slug'] ) === false )
bp_core_redirect( $path . $bp->bp_options_nav['groups']['forum']['slug'] . '/' );
}
add_action( 'wp', 'redirect_to_forum' );

Now when a member of your site clicks on a group, rather than being forwarded to the group’s activity tab, they will hit your forums instead! this stops new members getting confused by the activity stream and thinking that the activity stream is actually a forum! (You may laugh, but it happens!) icon smile Feature Your Forums And Get Them Noticed!

Trick 2 – Install Rich’s ‘latest Forum Posts’ Widget

Now this widget is a must have in my opinion. It is actually part of Rich’s ‘Forum Extras’ plugin which comes with heaps of extras for your forums. Be sure to check it out if you really want to add a lot of new functionality to your group forums. The code snippet below adds a new widget that displays the latest forum topics.

Copy this code into your bp-custom.php or functions.php file:

class MY_Latest_Topics_Widget extends WP_Widget {
function my_latest_topics_widget() {
parent::WP_Widget( false, $name = __( 'Latest Topics', 'buddypress' ) );
//if ( is_active_widget( false, false, $this->id_base ) )
}
function widget($args, $instance) {
global $bp;
//don't care to load on these pages
if ( bp_is_register_page() || bp_is_activation_page() || bp_is_user_blogs() )
return;
if ( $bp->forums->slug == $bp->current_component )
return;
if ( $bp->forums->slug == $bp->current_component && bp_is_directory() )
return;
//add in more here if you do not want to display this on certain pages (see bp-core-templatetags for list of built-in checks)
extract( $args );
if ( !is_numeric( $instance['forum_latest_limit'] ) )
$instance['forum_latest_limit'] = 10;
echo $before_widget;
echo $before_title
. $widget_name
. $after_title;
if ( bp_has_forum_topics( 'no_stickies=no&page=false&max='. $instance['forum_latest_limit'] ) ) : ?>
<ul class="item-list">
	<li>
<div class="item">
<div class="item-title">&lt;a class="topic-title" href="" title=" - "&gt;</div>
<span class="description">&amp;ndash posted in &lt;a href="" title=""&gt;</span>
</div></li>
</ul>
<div>
</div>
&lt;?php endif;
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['forum_latest_limit'] =  strip_tags( $new_instance['forum_latest_limit'] );
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'forum_latest_limit' =&gt; 10 ) );
$forum_latest_limit = strip_tags( $instance['forum_latest_limit'] );
?&gt;
<table class="form-table">
<tbody>
<tr>
<th>&lt;label for="get_field_id( 'forum_latest_limit' ); ?&gt;"&gt;</th>
<td>&lt;input id="get_field_id( 'forum_latest_limit' ); ?&gt;" name="get_field_name( 'forum_latest_limit' ); ?&gt;" type="text" value="" size="4" /&gt;</td>
</tr>
</tbody>
</table>
&lt;?php
}
}
function my_latest_topics_widgets_init() {
add_action('widgets_init', create_function('', 'return register_widget("MY_Latest_Topics_Widget");') );
}
add_action( 'bp_register_widgets', 'my_latest_topics_widgets_init', 15 );

Now go into your ‘widgets’ area in the WP backend and drag the ‘Latest Topics’ widget into your sidebar. You can set how many topics you want to display here too!

So there you have it! Hopefully your members will find your forums quicker and can now see what the latest chat is about when they are on any page of your site!

Get the conversation going!

About Bowe Frankema

 Feature Your Forums And Get Them Noticed! Building communities on BuddyPress is something I’m very passionate about. The decision to focus exclusively on BuddyPress projects over the last few years inspired me to share back some of the things I've learned here on BP-Tricks! You can find me on WordCamps & BuddyCamps across the globe and on Twitter! Follow me on Twitter

I'm constantly updating my BuddyPress Hosting Guide and SiteGround and WPEngine
have proven to be a great fit for hosting your BuddyPress community.

Need some help finding the perfect host? Check out my in-depth BuddyPress Hosting guide!
Tags: , ,

Discussion

23 responses to ‘Feature Your Forums And Get Them Noticed!

  1. Can trick 1 be done via functions.php as well ? I have searched high and low for a bp-custom.php file in my folders but I can’t seem to find it. I know you write that Trick 2 can be done via either the folder, so I was hoping you maybe accidentally forgot to include functions.php in the first trick as an option.

    Thanks in advance.

  2. Regarding trick 2 when is paste the code into my site is the following error.

    Parse error: syntax error, unexpected ‘&’ in /home3/jxxxxxxx/public_html/wp-content/themes/genesis-buddy-1.2.1/child-theme/functions.php on line 50

    line 50 is

    if ( $bp->forums->slug == $bp->current_component )

    Looks to me like its something in the code I copied from this post.

    Any Ideas?

  3. BTW, can anyone clue me in on a way to adapt this redirect for member profiles?

    I’ve tried myself but either wind up with extra trailing slashes in the URL, or a blank screen.

  4. Trick 2 created no widget for me. I pasted the code — after fixing the character encoding — into functions.php and then a bp-custom.php file and neither worked.

  5. I just want to mention I am just beginner to blogging and honestly loved you’re web-site. Almost certainly Im going to bookmark your website . You surely have beneficial articles. Kudos for sharing with us your blog site.

  6. Hi – code #1 above breaks my site.
    Trying to go from the Group directory to a group gets a blank page.
    Any ideas why?
    WPMU 3.0.1 and BP 1.26.
    Thanks – DV

  7. However this code which I found in the BP forums works !

    function redirect_to_forum() {
    global $bp;
    $path = clean_url( $_SERVER[‘REQUEST_URI’] );
    $path = apply_filters( ‘bp_uri’, $path );
    if ( bp_is_group_home() && $bp->current_action == $bp->bp_options_nav[‘groups’][‘home’][‘slug’] )
    bp_core_redirect( apply_filters( ‘bp_uri’, $bp->bp_options_nav[‘groups’][‘forum’][‘link’]) );
    }
    add_action( ‘wp’, ‘redirect_to_forum’ );

  8. I tried trick 1 – and it did not work. I have a function.php in my child theme – tried adding the code there nothing changed – I tried all a file bp-custom.php and placing the code in there – and nothing happened either?

  9. Neither tricks really work anymore. Dan V’s solution to trick 1 works. The code for trick 2 has had the character encoding all changed by this site, so you need to sort that out first (> should be a greater than symbol, for example). The widget is created, but doesn’t appear correctly. All I can see is “ posted in ” inside the widget… I don’t think it’s supposed to look like that.

      • Code needs to be updated for newer veorsin of buddypress and wordpress. Try a veorsin of this:bp_options_nav[$bp->groups->current_group->slug][‘home’][‘slug’] ) === false ) { if ($bp->groups->current_group->is_user_member || $bp->groups->current_group->status == public’) { bp_core_redirect( $path . forum/’ ); } }}function move_group_activity_tab() { global $bp; if (isset($bp->groups->current_group->slug) && $bp->groups->current_group->slug == $bp->current_item) { $bp->bp_options_nav[$bp->groups->current_group->slug][‘home’][‘position’] = ’98 ; $bp->bp_options_nav[$bp->groups->current_group->slug][‘home’][‘name’] = Something'; }}add_action( bp_init’, redirect_group_home’ );add_action( bp_init’, move_group_activity_tab’);?>

  10. Trick 1 does not work if utilizing the BP Groups Hierarchy plugin. Any ideas on how to just look at the group slug to see if it is “home” since subgroups have “home” slugs as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>