One of the great things about WordPress is the community of themers and the ease with which themes can be produced. Habari makes it pretty easy to produce themes as well, but, as a new product, there aren't that many themes around. To try and get a handle on the differences between the systems I decided to port over one of the great themes that are available for WordPress.

Rather than create a tutorial I decided to create a short reference guide to the functions and code I have changed. I think this is likely to be more useful to people looking to move over from WordPress. This isn't intended to be a guide to switching, or a comprehensive list of differences but a general introduction to what I have done with this theme.

Habari supports a number of different theme engines so depending on your background you might prefer different methods of theming. For WordPress however the RAWPHP engine is a pretty good match so that is what I will use.

The theme I have decided to use is the Dilectio by Design Disease. You can download the Habari version here.

This is the first theme I have moved across so if you find anything that doesn't work the way it should, please let me know. Similarly, if there is anything in this post that is confusing, or missed out, again, let me know.

The following tables include details of the changes that I have made. Note that in a lot of cases WordPress creates the HTML to go around the information whereas Habari gives you the data. Where this is the case for things such as links I have only included the Habari functions that output the important part, i.e. the URL.

Also note that most of the Habari content needs to be echod and not just inserted. I have not included the echo command in the examples.

This post is being written prior to the release of Habari 0.6

File names

File Names
DisplaysWordPressHabari
Home Pageindex.phphome.php
Single Postsingle.phpentry.single.php
Single Pagepage.phppage.single.php
Archivesarchives.phpRemoved
Posts by datearchive.phpmultiple.php
Categoriescategory.phpmultiple.php (for tags)
Attached Filesattachment.phpRemoved
Comments Popupcategory.phpRemoved
Theme Functionsfunctions.phptheme.php
Theme InformationIncluded in styles.cssAdded theme.xml

General Functions

Header / Blog Functions
FunctionWordPressHabari
Page Titlewp_title( args )See Page Title below
Template URLbloginfo('template_url');Site::out_url( 'theme' );
Blog Namebloginfo('name');Options::out( 'title' );
Blog Description / Taglinebloginfo('description');Options::out( 'tagline' );
Home Pageget_option('home'); or
bloginfo('url');
Site::out_url( 'habari' );
Stylesheet URLbloginfo('stylesheet_url');<?php Site::out_url( 'theme' ); ?>/style.css
Feed URLbloginfo('rss2_url');
bloginfo('rss_url');
bloginfo('atom_url');
$theme->feed_alternate();

Include Tags

Include Tags
FunctionWordPressHabari
Get Headerget_header();$theme->display( 'header');
Get Sidebarget_sidebar();$theme->display( 'sidebar');
Get Footerget_footer();$theme->display( 'footer');
Show Commentscomments_template();$theme->display ('comments');

Checking conditions

Checking Conditions
FunctionWordPressHabari
Whether there are any posts selectedhave_posts()count($posts) > 0
Comment Status$comment->comment_approved == '0'
( 0 = unapproved, 1 = approved )
$comment->status == Comment::STATUS_UNAPPROVED
( or Comment::STATUS_APPROVED )
Comments Permitted'open' == $post->comment_status (open or closed)$post->info->comments_disabled (true or false)
Plugins are loadedfunction_exists( plugin_function )See Theme Functions below

Page Menu

See Page Menu below

Page / Post Information

Post Information
FunctionWordPressHabari
The LoopSee The Loop below
Post IDthe_id();$post->id;
Post Permalinkthe_permalink()$post->permalink;
Post Titlethe_title();$post->title;
Formatting Post Datesthe_time( 'j M Y' )Format::nice_date( $post->pubdate , 'j M Y');
$post->pubdate->out('j M Y'); ( 0.6 onwards)
Post CategorySee Category Alternatives below
Post Authorthe_author()$post->author->displayname;
Post Contentthe_content()$post->content_out;
List the Tagsthe_tags( Arguments )$post->tags_out; (See also Tag Formatting below)
Single post comment feedcomments_rss_link('RSS 2.0');URL::out( 'atom_feed_entry_comments' , array( "slug" => $post->slug) );

Comments

Comments
FunctionWordPressHabari
Number of Commentscomments_number('None', 'One', '%' )$post->comments->moderated->count
Comment Loopforeach ( $comments as $comment )foreach ( $post->comments->moderated as $comment )
Comment IDcomment_ID()$comment->id;
Comment Authorcomment_author_link()Name: $comment->name;
URL: $comment->url;
Comment Datecomment_date('F jS, Y')Format::nice_date( $comment->date , 'j M Y');
$comment->date->out('j M Y'); ( 0.6 onwards)
Comment Timecomment_time();See Comment Date above
Comment Contentcomment_content();$comment->content_out;
Form Field Values
Commenter Name$comment_author$commenter_name
Commenter email$comment_author_email$commenter_email
Commenter Website$comment_author_url;$commenter_url
Comment ContentNone$commenter_content

Page Title

WordPress uses a built in function for displaying the page title: wp_title(). This is usually used with other text and conditions to change the order of the title for archives etc.

The title that is shown on the top of the page, for search or archives is usually put together within the theme using conditional statements; i.e. is_single, is_day, is_month, etc.

Habari encourages the use of functions within the theme.php file to keep the logic out of the template files so I have created a function in theme.php called the_title to calculate the correct title.

The function checks which rewrite rule has been matched by getting the value of $this->matched_rule->name This is equivalent to checking is_search, is_category, etc

The appropriate title is then calculated and returned.

It has one argument $head, which adds on the blog title to the end if it is intended to be used in the HEAD section of the HTML. Here is a small section of that function:

  1.  
  2. function the_title( $head ) {
  3.  
  4. switch( $this->matched_rule->name ){
  5. case 'display_entry':
  6. $title .= $this->post->title;
  7. break;
  8. case 'display_page':
  9. $title .= $this->post->title;
  10. break;
  11. }
  12.  
  13. if ( $head ){
  14. return ( empty($title)) ? Options::get( 'title' )
  15. : $title . ' - ' . Options::get( 'title' );
  16. }
  17.  
  18. return $title;
  19.  
  20. }
  21.  

Page Menu

The original WordPress theme used wp_list_pages to get a list of the pages, and then regular expressions to clean up the html that was generated. Habari doesn't have an equivalent function.

Instead I have created a function in theme.php that uses Posts::get to retrieve a list of posts and then looped through them to create an html list.

  1.  
  2. $options_array = array(
  3. "content_type" => 'page',
  4. "status" => Post::status('published'),
  5. "nolimit" => 1);
  6. $pages = Posts::get( $options_array );
  7.  
  8. foreach( $pages as $page ){
  9.  
  10. ....
  11.  
  12. }

The Loop

Habari doesn't uses a foreach instead of the WordPress While loop:

WordPress

  1.  
  2. if (have_posts()) : while (have_posts()) : the_post()
  3.  
  4. ...
  5.  
  6. endwhile; endif;
  7.  

Habari

  1.  
  2. foreach( $posts as $post ){
  3.  
  4. ...
  5.  
  6. }
  7.  

Category Alternatives

I believe future releases of Habari will feature the ability to use hierarchical categories. Or at least for plugins to be able to make use of that option. For the moment though it only uses tags.

Where this theme previously listed categories for each post I have simply replaced the list with a list of tags. In the sidebar though I wanted to limit the number of tags shown to more closely replicate the idea of using categories; i.e. that they represent significant subject divisions.

To do this I have created a function in theme.php that limits the tags that are displayed to those that are used in a given percentage of posts.

The call in sidebar.php to $theme->list_tags( 10 ) will list tags that are used in at least 10% of the posts.

Post Excerpts

WordPress has a tag the_excerpt();

Habari has a formatting function called Format::summarize that can produce an excerpt. I have used this to shorten the recent comments in the sidebar.

Habari also has a formatting function that can be attached to the post_content_out hook, so that it is not necessary to use it within the template itself. This is the more function, and it replaces the post output with an excerpt of a given length whenever the content is output on a page that lists more than one post, i.e. home, search, archives, etc.

This is applied by calling the following within the function action_init_theme in theme.php

  1.  
  2. Format::apply_with_hook_params( 'more',
  3. 'post_content_out',
  4. _t('Read More') . ' ยป' ,
  5. 100,
  6. 1 )
  7.  

Tag Formatting

The tags shown for each post are formatted by applying a formatting function to the tags_out hook. It takes the tags and creates an HTML list with an 'and' before the last tag.

This is applied by calling the following within the function action_init_theme in theme.php

  1.  
  2. Format::apply( 'tag_and_list', 'post_tags_out' );
  3.  

Password Protected Posts

Habari doesn't have them.

Theme Functions

The WordPress version of the theme checks to make sure that the appropriate function exists before calling it.

In Habari, plugins add methods to the theme object. Calling a theme method that doesn't exist does not trigger an error, therefore no further checks are needed.

Plugin Templates

There are some additional files in the theme folder: filckrfeed.php and blogroll.php. These contain a template to override the default included with those plugins.

Links to plugins

The plugins can be got from http://www.habariproject.org/dist/plugins/

The plugins required for this theme are: Blogroll, Monthly Archives and FlickrFeed