Habari Tips & Tricks
Not too long ago my wife asked me to set up a blog for her, so she could stay in contact with those we left behind in Kentucky. Since I had been wanting her to blog for a couple of years now, I immediately set to work figuring out a domain for it, and designing a theme.
She didn't want a vanity domain, so I settled on WeDavis3 as a suitably short, descriptive URL for the site. I had been planning on blogging more about everyday life, so moving that to the new site made a certain amount of sense.
Now, to the fun part
Now that I had a domain, I started thinking about how I would present the content. Since there would be two of us blogging on the site, it made a certain amount of sense to present our newest posts side-by-side, with a list of older content under each persons newest post.
I quickly mocked up (in HTML the only way to design!) what I wanted it to look like, and once the template was done I moved on to figuring out how I wanted to coax Habari into giving me the content in the manner I had chose.
Thankfully, this is dead simple in Habari. In the next couple of paragraphs I will walk you through how I accomplished the layout seen on WeDavis3.com.
Ah the power of cheese, err Habari
First, it is important to understand how the theme.php file that comes with each theme works. Thankfully Skippy has already done a wonderful job providing a quick overview of theme.php, so you should go read it. Don't worry I will be here when you get back.
Okay, now that you have a better understanding of what theme.php was designed for, lets outline what we need. First we need to grab the newest published post from both authors on the site and display them, then we need to grab the newest (n) posts, excluding the newest one, from each author and display those as well.
Lets see the code
The easiest way to do this is to make 4 calls and assign them each to a theme variable. Don't believe me, check out the code:
// then two more custom loops for a selection of posts from
// two custom loops for pulling the newest posts from our
// two authors.
$this->assign( 'hnewests', Posts::get( array( 'user_id' => 2,
'limit' => 1 ) ) );
$this->assign( 'cnewests', Posts::get( array( 'user_id' => 1,
'limit' => 1 ) ) );
// their recent pasts.
$this->assign( 'harchives', Posts::get( array( 'user_id' => 2,
'limit' => 5 ) ) );
$this->assign( 'carchives', Posts::get( array( 'user_id' => 1,
'limit' => 5 ) ) );
In a nutshell, we are telling Posts::get()
that we want the newest post for user 2, and user 1, binding them to hnewests and cnewests respectively and then telling Posts::get()
to give us the 5 most recent posts from each user. We then process the second array on the front end to remove the post that was fetched in our first set of calls.
Now that we have created our custom loops and assigned them, calling them in our home.php template becomes laughably easy. Here is an example of displaying the newest post from user h:
And that is it
At this point you should be pulling content for both authors and placing them in easily accessible arrays. All that is left is to decide where and how to display them in your theme. To see this code in action, check out wedavis3.com.
Enjoyed this article? Follow me on Twitter.
title="">
comments->approved->count; ?>