<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Justin Tadlock &#187; bbPress Tutorials</title>
	<atom:link href="http://justintadlock.com/tags/bbpress-tutorials/feed" rel="self" type="application/rss+xml" />
	<link>http://justintadlock.com</link>
	<description>Life, Blogging, and WordPress</description>
	<lastBuildDate>Sun, 07 Feb 2010 08:25:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to create custom views in bbPress</title>
		<link>http://justintadlock.com/archives/2009/07/15/how-to-create-custom-views-in-bbpress</link>
		<comments>http://justintadlock.com/archives/2009/07/15/how-to-create-custom-views-in-bbpress#comments</comments>
		<pubDate>Thu, 16 Jul 2009 03:16:42 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[bbPress]]></category>
		<category><![CDATA[bbPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1743</guid>
		<description><![CDATA[A tutorial on creating custom views for bbPress that covers creating the views, listing them, and making custom templates to handle their display.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">I</span>n bbPress, we have these things called <em>views</em>.  Views are used to show a certain, well, view of your topics, posts, users, and so on depending on the purpose of the view.  Several plugins offer alternative views (e.g., highest rated topics, most posts, etc.).</p>
<p>Fortunately, bbPress comes loaded with a function called <code>bb_register_view()</code> that makes this extremely simple.  I&#8217;ll be showing you how to create new views in this tutorial.</p>
<p>Some things worth noting:</p>
<ul>
<li>Views are displayed according to the <code>view.php</code> file within your theme.</li>
<li>bbPress comes loaded with with two default views: &#8220;Topics with no replies&#8221; and &#8220;Topics with no tags.&#8221;</li>
<li>The <a href="http://bbpress.org/plugins/topic/my-views" title="My Views bbPress plugin">My Views</a> plugin creates some neat views and is definitely worth checking out.</li>
</ul>
<p>Here&#8217;s a look at some custom views I&#8217;ve create:</p>
<div id="attachment_1744" class="wp-caption aligncenter" style="width: 610px"><img src="http://justintadlock.com/blog/wp-content/uploads/2009/07/custom-views.png" alt="Custom bbPress views" title="Screenshot of custom views in bbPress" width="600" height="327" class="size-full wp-image-1744" /><p class="wp-caption-text">Custom bbPress views</p></div>
<h2>The bb_register_view() function</h2>
<p><code>bb_register_view()</code> is the function that handles creating new views.  Let&#8217;s take a look at its parameters and what we can do with them.</p>
<pre><code>bb_register_view( $view, $title, $query_args = '', $feed = TRUE );</code></pre>
<p><code>$view</code> is what you&#8217;ll name the view.  What you put here will also become part of the permalink to the view page.</p>
<p><code>$title</code> is the title of the view that you&#8217;ll see on screen.  It&#8217;ll show in view lists and likely on your view page.  <em>Note:  Theme and plugin developers should localize this so it can be translated.</em></p>
<p><em>Optional:</em>  <code>$query_args</code> should be an array of arguments on how to display the topics and such on the view&#8217;s page.</p>
<p><em>Optional:</em>  <code>$feed</code> is whether the view should have its own feed.  This is set to <code>true</code> by default.</p>
<h2>Creating a custom view</h2>
<p>Now that you know how the <code>bb_register_view()</code> function works, it&#8217;s time to create a couple of views.  The first thing you should do is open your theme&#8217;s <code>functions.php</code>.  If your theme doesn&#8217;t have this file, create one.</p>
<p>We&#8217;ll create two new views: Alphabetical (ascending) and Alphabetical (descending).  Drop this code in your <code>functions.php</code> file:</p>
<pre><code>&lt;?php

add_action( 'bb_init', 'my_custom_views_init' );

function my_custom_views_init() {
	$args = array( 'order_by' => 'topic_title', 'order' => 'ASC' );
	bb_register_view( 'alphabetical-ascending', __('Alphabetical: Ascending (A &ndash; Z)', 'example'), $args, false );

	$args = array( 'order_by' => 'topic_title', 'order' => 'DESC' );
	bb_register_view( 'alphabetical-descending', __('Alphabetical: Descending (Z &ndash; A)', 'example'), $args, false );
}

?></code></pre>
<p>In your views list, you should now be able to click on either of these views and see what happens.</p>
<h2>Custom view templates</h2>
<p>By default, bbPress will use your theme&#8217;s <code>view.php</code> template to display a view.  Sometimes, you might want to create an entirely custom template though, which is perfectly fine.</p>
<p>For the sake of simplicity, we&#8217;ll create two new templates with the same names as our views from above:  <code>alphabetical-ascending.php</code> and <code>alphabetical-descending.php</code>.  Place those files in your theme&#8217;s folder.</p>
<p>Then, add this code to your <code>functions.php</code> file:</p>
<pre><code>&lt;?php

add_action( 'bb_custom_view', 'my_custom_views_templates' );

function my_custom_views_templates( $view ) {

	if ( 'alphabetical-ascending' == $view ) {
		bb_load_template( 'alphabetical-ascending.php' );
		exit();
	}
	elseif ( 'alphabetical-descending' == $view ) {
		bb_load_template( 'alphabetical-descending.php' );
		exit();
	}
}

?></code></pre>
<p>Of course, what goes in your custom templates is entirely up to you.  Use your imagination.</p>
<p class="note">Note:  There may be a more elegant way to load custom view templates, so if you have suggestions, I&#8217;d love to hear them.</p>
<h2>How to list your views</h2>
<p>Most bbPress themes will likely list your views somewhere within the theme, but if yours doesn&#8217;t, just drop this code wherever you need to list them:</p>
<pre><code>&lt;ul>
	&lt;?php foreach ( bb_get_views() as $view => $title ) : ?>
		&lt;li class="view">&lt;a href="&lt;?php view_link( $view ); ?>" title="&lt;?php view_name( $view ); ?>">&lt;?php view_name( $view ); ?>&lt;/a>&lt;/li>
	&lt;?php endforeach; ?>
&lt;/ul></code></pre>
<h2>Views are not pages</h2>
<p>On a final note, I wanted to point out that views are not pages.  bbPress is not a <acronym title="Content Management System">CMS</acronym> like WordPress, which is what you&#8217;d use to create things like pages.  One could use views to create <em>ad hoc</em> pages, but this seems a bit crude.</p>
<p>I can see the need for something like a page feature for forum-only sites, but I&#8217;ll leave that discussion for another time.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/07/15/how-to-create-custom-views-in-bbpress/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>How to create a forums list in bbPress</title>
		<link>http://justintadlock.com/archives/2009/05/03/how-to-create-a-forums-list-in-bbpress</link>
		<comments>http://justintadlock.com/archives/2009/05/03/how-to-create-a-forums-list-in-bbpress#comments</comments>
		<pubDate>Sun, 03 May 2009 23:40:58 +0000</pubDate>
		<dc:creator>Justin Tadlock</dc:creator>
				<category><![CDATA[bbPress]]></category>
		<category><![CDATA[bbPress Tutorials]]></category>

		<guid isPermaLink="false">http://justintadlock.com/?p=1639</guid>
		<description><![CDATA[How to create a list of your forums for bbPress with a link to each forum, its <acronym title="Really Simple Syndication">RSS</acronym> feed, and number of posts.]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">W</span>hile redesigning the Theme Hybrid <a href="http://themehybrid.com/support" title="Theme Hybrid support forums">support</a> and <a href="http://themehybrid.com/community" title="Theme Hybrid community forums">community</a> forums, I needed an easy way to show off the list of forums with links to the <acronym title="Really Simple Syndication">RSS</acronym> feeds and number of posts next to each forum name.  </p>
<p>What I&#8217;ll be showing you in this tutorial is a simple way to do this.</p>
<p>I prefer to have the list of forums in the sidebar while showing the most recent posts in the content area.  But, you can use this code in any of your template files for use anywhere on your forums.</p>
<h2>The code</h2>
<p>What we&#8217;ll be doing is using the <code>get_forums()</code> function to grab an array of all of your forums.  Then, we&#8217;ll loop through the array, listing a link to each forum, showing the number of posts, and linking to the <acronym title="Really Simple Syndication">RSS</acronym> feed.</p>
<pre><code>&lt;div class="forums-list"&gt;

	&lt;h3&gt;Forums&lt;/h3&gt;

	&lt;ul&gt;

	&lt;?php $forums = get_forums(); ?&gt;
	&lt;?php foreach ( $forums as $forum ) : ?&gt;

		&lt;li&gt;
			&lt;a class="forum-link" href="&lt;?php forum_link( $forum-&gt;forum_id ); ?&gt;"&gt;&lt;?php forum_name( $forum-&gt;forum_id ); ?&gt;&lt;/a&gt;
			&lt;span class="forum-posts"&gt;(&lt;?php forum_posts( $forum-&gt;forum_id ); ?&gt; posts)&lt;/span&gt;
			&lt;a class="rss-link" href="&lt;?php bb_forum_posts_rss_link( $forum-&gt;forum_id ); ?&gt;"&gt;(&lt;abbr title="Really Simple Syndication"&gt;RSS&lt;/abbr&gt;)&lt;/a&gt;
		&lt;/li&gt;

	&lt;?php endforeach; ?&gt;

	&lt;/ul&gt;

&lt;/div&gt;</code></pre>
<h2>The finished product</h2>
<p>I worked a little extra <acronym title="Cascading Style Sheets">CSS</acronym> magic on mine and came up with this:</p>
<p><img src="http://justintadlock.com/blog/wp-content/uploads/2009/05/bbpress-forums-list.png" alt="bbPress Forums List" title="bbPress Forums List" width="600" height="343" class="aligncenter size-full wp-image-1640" /></p>
<p>I hope you have fun with this code and come up with more unique ways to show off your forums.  I provided a few <acronym title="Cascading Style Sheets">CSS</acronym> classes to help you out if you want to add your own style.  Here they are for reference:</p>
<pre><code>/* Containing &lt;div&gt; */
.forums-list {}

/* Header */
.forums-list h3 {}

/* List */
.forums-list ul {}
.forums-list li {}

/* Forum link */
a.forum-link {}

/* Number of forum posts */
span.forum-posts {}

/* Forum RSS Link */
a.rss-link {}</code></pre>
<h2>More bbPress tutorials and discussion to come</h2>
<p>I&#8217;m not really sure how many folks are using <a href="http://bbpress.org" title="bbPress forum software">bbPress</a> these days, but it&#8217;s the forum software of choice for me.  It&#8217;s simple and lightweight &mdash; everything I need in forum software.  I hope that I can bring more people to this platform and do my part in helping the bbPress community grow.</p>
<p>I also hope to continue writing more tutorials like this one, so there&#8217;ll be more documentation out there.  If you have ideas for tutorials, I&#8217;ll see if I can squeeze them in sometime.</p>
]]></content:encoded>
			<wfw:commentRss>http://justintadlock.com/archives/2009/05/03/how-to-create-a-forums-list-in-bbpress/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
