Tags
From Habari Project
Tags allow you to organize your posts into groups, much like the Gmail ‘labels’ system. A blog post can have more than one tag, and you can find a complete list of all the tags used in your blog on the Create Entry page.
To list all of the tags used on your site, you will need to edit 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 can be named something different.
First, we are going to add the following code into your custom Class.
if( !$this->template_engine->assigned( 'all_tags' ) ) { // List of all the tags $tags= DB::get_results( 'SELECT tag_text as tag, tag_slug as slug FROM ' . DB::table('tags') . ' ORDER BY tag_text ASC' ); $this->assign('all_tags', $tags); }
You can change the order your tags are displayed by setting the 'ORDER BY tag_text ASC' to either 'asc' which will sort from lowest to highest, or 'desc' which will sort from highest to lowest. By low and high, here we mean alphabetical order, 'A' being highest and 'Z' being lowest.
To display a list of your used tags you need to use the following:
<?php if( count( $all_tags ) > 0 ) { ?> <ul class="tags"> <?php foreach($all_tags as $tag) { ?> <li> <a href="<?php Site::out_url( 'habari' ); ?>/tag/<?php echo $tag->slug; ?>/" rel="tag" title="<?php echo $tag->tag; ?>"> <?php echo $tag->tag; ?> </a> </li> <?php } ?> </ul> <?php } ?>
This will output your tags as an unordered list which you can style with CSS.
