Asides

From Habari Project

Jump to: navigation, search

Asides, or short posts, are a common feature in blogs. These are generally a few lines, and intended to be outside the loop of larger posts. It's quite common it show these in a sidebar or big footer.

To accomplish this with Habari, you will employ the use of tags. Your first order is to determine what tag you want to use. In this example "aside" will be used.

The first file you will be editing will be your theme.php file.

You will be adding a few lines to your custom Class. (In k2 this class is called myTheme, your custom theme should be named something different)

First, we are going to exclude the aside tag from the main loop.

public function act_display( $user_filters = array() )
{
	parent::act_display( array( 'vocabulary' => array( 'tags:not:term' => 'aside' ) ) );
}

(Note, if you use a different tag other than "aside", you will need to change it in all the code examples).

Next you are going to define a variable so that you can control how many posts to show, and output the list of posts.

$this->assign( 'asides', Posts::get( array( 'tag'=>'aside', 'limit'=>5) ) );
parent::add_template_vars();

You can obviously change the limit variable to alter the number of items you are going to output.

Now that the theme.php file has been edited, the "aside" tag is excluded from the main loop of posts, and you are ready to output your list of asides. Determine where you want to output this list (as mentioned, a sidebar is a very common place).

<ul>
<?php
foreach($asides as $post):
echo '<li><span class="date">';
echo $post->pubdate_out . ' - ' . '</span>';
echo '<a href="' . $post->permalink .'"/>' . $post->title_out . '</a> - ';
echo '</li>'; ?>
<?php endforeach; ?>
</ul>

In this example, Only the post title and a permalink to the post is shown. You can add echo $post->content_out; where you want it shown in the foreach (ie, before the closing </li>)

You may also want to read over Using Excerpts if you want to have full length posts in your main content, and excerpts for your asides.

Here is another tutorial for doing inline asides. That is, asides listed along with primary posts, however with the ability to format them differently.

Personal tools