Quantcast
Channel: BP-Tricks » Coding
Viewing all articles
Browse latest Browse all 11

Feature Your Forums And Get Them Noticed!

$
0
0

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!

- - - - - - - - You've finished reading Feature Your Forums And Get Them Noticed! on BP-Tricks.


Viewing all articles
Browse latest Browse all 11