now/Asides with Habari

now/Content

So I thought I would outline the process I used to achieve the inline asides effect you are seeing on Sillyness. This was one of those moments where I just love how Habari handles things.

So lets set the stage

So this is what we are going to do. First we choose a tag that we will use to identify our asides. I chose “quickie”. Once we have settled on a tag that will be used, we create at least one entry that uses the tag.

Once we have some content to test with, we move on to some PHP goodness. Habari returns an array of tags within the $post object. Normally we would make a call to the tags like so:

echo $post->tags_out; or echo $post->tags;

You will notice that there are two ways to call for your tags. We will be using both calls in this little tutorial. The first call gives you the tag array without any formatting filters applied. Habari allows you to create functions that interact with your content, in this instance if you wanted to do some extra formatting to your tags, you would write a function and call it like this:

Format::apply('my_function', 'post_tags_out');

Now anytime you call $post->tags_out Habari will apply your function to the tags before they are displayed. Very cool.

Now back to the task at hand. To style our “asides” posts differently we need to start our loop, and look through the tags array for each post and if we find our tag, in this case “quickie” we style the post differently. Here is the code to do just that:

<?php foreach ( $posts as $post ) { ?><br />
<?php if( in_array('quickie', $post->tags ) ) { ?><br />
<div id="post-<?php echo $post->id; ?>"><br />
<p class="quickie"><br />
<a href="<?php echo $post->permalink; ?>" rel="bookmark" title='
<?php echo $post->title; ?>'><
?php echo $post->title_out; ?></a> » <?php echo $post->content; ?> 
<a href="<?php echo $post->permalink; ?>#comments" 
title="Comments on this post">
(<?php echo $post->comments->approved->count; ?>)</a><br />
</p><br />
</div><br />
<?php } else { ?><br />
// We are seeing normal posts.<br />

So, as you can see all we really have to do is call in_array(), pass it the tags array and the tag we are looking for and we are done.

You will notice that I am calling $post->tags, instead of $post->tags_out. This is important since we need an array to look through, not formatted text.

And that is it. With this code we have implemented inline asides. Pretty cool huh?

now/Information




comment/Content

comment/Information


  1. personal avatar

    Hi, don’t you have already explain it there ? 
    http://www.chrisjdavis.org/quick-posts



  2. personal avatar

    Very, very cool indeed. It’s nice to see a little of the Habari underbelly at work.



  3. personal avatar

    Fred,

    Hi, don’t you have already explain it there ? http://www.chrisjdavis.org/quick-posts

    Hmmm, you know what Fred… I completely forgot about writing that. Well that is embarrasing isn’t it?



  4. personal avatar

    No, still pretty cool :)

    Keep going on Habari, it’s gonna be a great tool. You could say to Owen that he should add “internationalization” to his todo list.



  5. personal avatar

    Hey Fred,

    We already have the framework in place to support internalization. We just need some people working on writing translation files.

    Looking for something to do Fred?



  6. personal avatar

    Yes Chris, I am. Could you send me a mail with the details because I don’t know where to start.



  7. personal avatar

    I would be more than interested to translate Turkish language files for you.

    BTW, its scary to see a post with id number 666, especially when it is your first repeated post :)



  8. personal avatar

    That would be great Ant. I will email you some information when I get a moment, but for now the best thing to do is get on the mailing lists and start participating.



  9. personal avatar

    Well, i would gladly translate Habari into danish, if Michael isn’t doing that already :)



  10. personal avatar

    I don’t know whether the fault is on my side, but design of your web, esspecially this one and these asides, is punished by IE7 :D … No problem with FireFox and Opera.
    The comments are flying on my screen like a dying bat :)



  11. personal avatar

    … 为Habari添加Asides”>为Habari添加Asides Chris在其博客上发布一篇habari的技巧,为你的habari博客添加asides。从其提供的办法来看,手动添加asides的灵活性还是很高的。 




comment/Body

comment/Meta



media/Flickr





media/LastFM

http://www.last.fm/music/Cake/_/Stickshifts+and+Safetybelts
http://www.last.fm/music/Poor+Old+Lu/_/Bones+are+Breaking
http://www.last.fm/music/Billy+Joel/_/Hey+Girl
http://www.last.fm/music/Gorillaz/_/Feel+Good+Inc
http://www.last.fm/music/ZZ+Top/_/Certified+Blues
http://www.last.fm/music/Da+Vinci%27s+Notebook/_/Blue+Moon
http://www.last.fm/music/The+Beatles/_/Can%27t+Buy+Me+Love
http://www.last.fm/music/KISS/_/Nothin%27+to+Lose
http://www.last.fm/music/KISS/_/See+You+Tonight
http://www.last.fm/music/Natasha+Bedingfield/_/These+Words
http://www.last.fm/music/Cake/_/Sheep+Go+to+Heaven
http://www.last.fm/music/Model+Engine/_/Drawing+Lines
http://www.last.fm/music/The+Temptations/_/Sugar+Pie+Honey+Bunch
http://www.last.fm/music/Sting/_/This+Cowboy+Song
http://www.last.fm/music/Barenaked+Ladies/_/The+King+of+Bedside+Manor
http://www.last.fm/music/Billy+Joel/_/The+Downeaster+%27Alexa%27
http://www.last.fm/music/Alanis+Morissette/_/You+Learn
http://www.last.fm/music/Barenaked+Ladies/_/I+Love+You
http://www.last.fm/music/ZZ+Top/_/Waitin%27+for+the+Bus
http://www.last.fm/music/Foo+Fighters/_/Another+Round