bbPress sidebar widget for WordPress
This is my first shot at writing a sidebar widget for WordPress. Not much complexity here but it does its job well.
About
I recently added a forum to this site and needed a clean way to display login / logout, register, and profile links. The sidebar seemed the most likely place to have these links but since I was using a theme that used widgets in the sidebar it wasn't quite as simple as just editing sidebar.php like I would normally do. Plus it was a good excuse to write a widget which is something I've been looking at doing for a while.
What this widget does is display the links, but only when you're in bbPress. If the bbPress files aren't loaded then the function displays nothing. That way it's not taking up space for visitors that aren't in your forum.
The Code
The code is only 45 lines including 8 lines of comments. You can copy and paste it from the block below, but it's probably easier just to download the zip file from the link at the end of this post.
-
<?php
-
/*
-
Plugin Name: bbPress Forum Widget
-
Plugin URI: http://forumsblogswikis.com/2008/04/06/bbpress-sidebar-widget-for-wordpress/
-
Description: Adds a widget to WordPress to allow users to login to bbPress
-
Author: Ryan Nutt
-
Version: 0.01
-
Author URI: http://forumsblogswikis.com
-
*/
-
-
function bbWidget($args)
-
{
-
{
-
echo $before_widget;
-
echo '<ul>';
-
if (is_user_logged_in())
-
{
-
$tmp = bb_get_admin_link();
-
if ($tmp)
-
{
-
}
-
}
-
else
-
{
-
}
-
echo '</ul>';
-
echo $after_widget;
-
}
-
}
-
-
function bbWidget_init()
-
{
-
register_sidebar_widget(__('bbPress Forum Widget'), 'bbWidget');
-
}
-
-
add_action('plugins_loaded', 'bbWidget_init');
-
?>
Example
Well, you're on it. Click on the Forum page on the sidebar and you'll see the widget fire up.
Download
Or, if you'd rather just download it...
[download id="2"]
And a favor
If you use this widget, drop in a comment below and let me know. I'd like to know where it's showing up. Plus I'm always looking for new forums to visit.
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.
I added the widget and NOTHING happened! I run WP2.5.1 and bbPress 0.9.0.2
Are you using the same theme for both your forum and blog? From within the blog it won’t do anything. It only displays when you’re in the forum, and your forum theme has to include the wp-blog-header.php file and use the sidebar widget functions.
I love how your forum is ‘inside’ your website. I downloaded your widget and activated it but nothing happened.
What steps did you take (or website tutorial) in order to get the matched Header/Sidebar from your blog.
I want my forum to look like yours (‘inside’ the site) – is this possible simply with your widget plugin?
Thanks!
You have to merge the themes a little, which is more than this widget was designed to do. The only thing that this widget does is display links for the forum when you’re using the forum. If you look to the right of this page the section isn’t there because we’re in the blog part right now. But if you click on the forum link you’ll see the forum section.
What I did was add require_once(‘/path/to/wordpress/wp-blog-header.php); to the bb-config.php file so that the blog page functions were available to my bbPress theme. Then, just have the header and footer templates for bbPress call the WordPress template functions.
Hi, This is exactly what I was looking for and I want to add it to my bbpress theme. I was wondering if the code will work for WordPress 2.7? Thanks.
Don’t see any reason why not.
Thank a lot.