Welcome to another tutorial on the Character bbPress theme. Character theme is extensively customizable, more so because of the hooks we’ve incorporated in the templates. In simple language hooks are like events to which you can attach your custom functionality. For example you can have your custom function called/executed whenever the footer of the theme is rendered. This no the actual definition or description of hooks but this is pretty much what happens when you use hooks. Check out our previous article for a list of all the hooks in the Character theme.

Generally your custom functions can be added directly to a themes templates or the functions file. However Character is a theme which keeps things organised so that the code is easy to edit, maintain and customize. All your custom functions will go into the user_functions.php file under the user directory of Character. That way all your customizations will be at one place where you’ll be able to edit them or back them up easily. Now let’s start with an example usage of a hook. Let’s try to add a link to the navigation menu (which is right above the header). As you know from the list of the hooks in Character, one of the hooks is ‘ch_hook_last_nav_item’ and it fires after the last link in the header. We are going to attach (the right verb is ‘hook’) a custom PHP function to this hook to display this link. Paste the following in your user_functions.php file:

function show_blog_url() {
 ?>
 <li><a href="http://www.binaryturf.com">Binary Turf</a></li>
 <?php
 }

add_action('ch_hook_last_nav_item','show_blog_url','11');

The last line starting with add_action attaches our custom function ‘show_blog_url’ to the hook ‘ch_hook_last_nav_item’. The ’11′ stands for priority, so if multiple functions are hooked to the same hook, the highest priority is given to the one with a priority of ’1′. So this function ‘show_blog_url’ executes whenever the hook ‘ch_hook_last_nav_item’ is triggered (and it triggers every time the header navigation menu is displayed). You can use this example to display your blog’s url or homepage to your forums. To summarize, here’s what you need to do step-by-step in order to customize Character.

  1. Define and understand your objective.
  2. Create your custom function which will create the functionality you require (like ‘show_blog_url’ in the above example).
  3. Attach it to the right hook using ‘add_action’ (as in the last line of the above code).

Suggestions and feedback are welcome. Questions go to the forums.

{ 0 comments }

Here’s a reference of the hooks in Character bbPress theme as of version 1.0

  • ch_hook_before_html: After the opening <body> tag.
  • ch_hook_after_html: Before the closing </body> tag.
  • ch_hook_before_header: Before the div#header opens.
  • ch_hook_after_header: After the div#header closes.
  • ch_hook_before_title: Before the #logo opens.
  • ch_hook_after_title: After the #tagline closes.
  • ch_hook_before_content_box: Before div#content opens.
  • ch_hook_after_content_box: After div#content closes.
  • ch_hook_first_nav_item: Before the first li in .menu (the header menu).
  • ch_hook_last_nav_item: After the last li in .menu but before li.rss (the header menu).
  • ch_hook_before_content: After div#content opens.
  • ch_hook_after_content: Before div#content closes.
  • ch_hook_before_sidebars: After div#sidebars opens.
  • ch_hook_before_widgets: After ul.sidebar_list opens.
  • ch_hook_after_widgets: Before ul.sidebar_list closes.
  • ch_hook_after_sidebars: Before div#sidebars closes.
  • ch_hook_before_footer: Before div#footer opens.
  • ch_hook_footer: First thing inside div#footer
  • ch_hook_after_footer: After div#footer closes.
  • ch_hook_first_footernav_item: After #footer_menu div#footer opens.
  • ch_hook_last_footernav_item: Before #footer_menu div#footer opens.
  • ch_hook_before_headline: Varies. Mostly this fires right after div.headline tag opens. Set the Debug option to “On” to verify the location of this hook on individual pages.
  • ch_hook_after_headline: Varies. Mostly this fires right before div.headline tag closes. Set the Debug option to “On” to verify the location of this hook on individual pages.
  • ch_hook_before_topic_headline: Fires on the Topic page right after ch_hook_before_headline.
  • ch_hook_after_topic_headline: Fires on the Topic page right before ch_hook_after_headline.
  • ch_hook_topicinfo: Fires on the Topic page inside div.infobox. Used to attach the topic info into the sidebar.
  • ch_hook_before_post: Fires before div.threadauthor on Topic page.
  • ch_hook_after_post: Fires after div.threadpost on Topic page.
  • ch_hook_before_post_meta: Fires after div.threadauthor opens; on Topic page only.
  • ch_hook_after_post_meta: Fires before div.threadauthor closes; on Topic page only.
  • ch_hook_404_title: Fires on 404 template/pages only. Used to attach 404 page title to the 404 error pages.
  • ch_hook_404_content: Fires on 404 template/pages only. Used to attach 404 page content to the 404 error pages. this is the only child of div.container_404.
  • ch_hook_postform_field: Fires on the post porm after the post form title. Can be used to attach additional fields to the post form.
  • ch_hook_postform: Fires right before the ‘post_form’ hook. This is before the submit button on the post form.
  • oip_login: Fires on the login page only if OpenID Plus plugin is installed.
  • post_post_form: Fires after the post form.
  • before_pos_n: Fires on the Topic pages before the post content (text) of every post. Substitute n for the post position (which can be retreived by get_post_position() bbPress template function). Thus you can use it like before_pos_4 to attach AdSense before the content of every topic page’s 4th post’s.
  • after_pos_n: Fires on the Topic pages after the post content (text) of every post. Substitute n for the post position (which can be retreived by get_post_position() bbPress template function). Thus you can use it like after_pos_4 to attach AdSense after the content of every topic page’s 4th post’s.
  • after_post_n: Fires on the Topic pages after the div.threadpost of every post. Substitute n for the post position (which can be retreived by get_post_position() bbPress template function). Thus you can use it like after_post_4 to attach AdSense after every topic page’s 4th post’s.

Bonus bbPress Hooks

  • post_form: Fires right before the submit button on the post form.
  • edit_form_pre_post: Fires before #post-form-post-container on the edit form.
  • topicmeta: Fires after the topic meta block.
  • extra_profile_info: Fires on the registration form before the submit button. Can be used to attach extra fields to the registration form.
  • bb_foot: Fires after the bbPress footer.
  • post_form_pre_post: Fires before the #post-form-post-container.
  • under_title: Fires after the topic title.
  • tag_above_table: Fires before the topics table when viewing the posts on the single tag page.
  • tag_below_table: Fires after the topics table when viewing the posts on the single tag page.

With all these hooks, customizing the Character bbPress theme is never an issue. You can customize it extensively or even turn bbPress into a web application! Subscribe to the RSS and watch this space for a small tutorial on how to use hooks.

{ 2 comments }

Troubleshooting Character Theme and bbPress

April 24, 2010

Here are a few tips just in case bbPress or other technologies play tricks with you. As we find more issues we’ll keep updating this page. If you know of some common problems and solutions please report in the comments section. The bbPress forum gets broken when I activate Character (or some other theme). What [...]

Read the full article →

How to Install & Setup Character

April 19, 2010

Installing Character is easy and just like the installation of any other bbPress theme. Here’s a quick step-by-step walk-through. Download and extract Character to any folder on your hard-drive. This should create a folder “character” with all the templates inside it . Verify that there’s a folder “my-template” in the root of your bbPress installation [...]

Read the full article →

Know your Character Theme Membership Benefits

April 19, 2010

When you sign-up for Character, you are entitled to several benefits. While you use Character, it’s good to know what these benefits are and how you can make use of them: Support Forums When you sign-up for Character, you get access to the premium membership of Binary Turf Support Forums — you have access to [...]

Read the full article →

Character version 1.0 released

March 23, 2010

We are pleased to announce the initial release of the Character bbPress Theme Framework. This initial version took more than a month to be developed from scratch. From creating a template system, a perfect and customizable layout, typography, options panel, and then to beta testing and release, the journey has been filled with excitement. Character [...]

Read the full article →