I've been using, contributing and hacking around Habari for some time now and I thought it's about time I started sharing my knowledge in a series of "Habari HOWTO" posts. This is the first in what will hopefully turn out to be a large valuable list for Habari users.

This question was posed on the habari-users group by manda:

I'm looking to set my home.php to show only 2 posts, but leave all other entry.multiple.php show whatever default number I set in Habari options (whether it be 5, 10 or 20). Is there something simple to add to home.php to tell it to show only 2 posts? Have not found anything on the wiki or forums regarding this, and trying to accomplish without a plugin (not even sure if there is a plugin available anyways). using trunk version.

In order to reduce the effect on performance by this change, you actually want the query to only pull the two posts you want rather than pulling the number you've configured (10 by default) and then only display the first two. There are actually two ways of doing this:

  1. Via a plugin

    The customquery plugin allows you to change the number of posts on the home page, and others.

  2. Via code directly in your theme.

    The following code added to the theme class within the theme.php file supplied with your theme will do the trick:

    public function act_display_home( $user_filters = array() )
    {
            parent::act_display_home( array( 'limit' => 2 ) );
    }

    All other pages will continue to use the value saved in your "Items per Page" option within the Habari configuration (Dashboard → Options).

My preference is for the latter as it doesn't involve installing another plugin and means if I chose to distribute the theme, it wouldn't require the user to install a plugin to get all the functionality required.

My inspiration for using this method came from a combination of the customquery plugin and the method detailed in the "asides" wiki page which uses a more generic action. As I was already using a similar line for asides, I thought I'd just extend it to limit the pages rather than use a plugin which essentially does just this.