now/Asides with Habari
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 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?
comment/Content
comment/Information
Hi, don’t you have already explain it there ?
http://www.chrisjdavis.org/quick-posts
Very, very cool indeed. It’s nice to see a little of the Habari underbelly at work.
Fred,
Hmmm, you know what Fred… I completely forgot about writing that. Well that is embarrasing isn’t it?
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.
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?
Yes Chris, I am. Could you send me a mail with the details because I don’t know where to start.
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 :)
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.
Well, i would gladly translate Habari into danish, if Michael isn’t doing that already :)
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 :)
… 为Habari添加Asides”>为Habari添加Asides Chris在其博客上发布一篇habari的技巧,为你的habari博客添加asides。从其提供的办法来看,手动添加asides的灵活性还是很高的。 …
media/Flickr
media/LastFM
old/Archives
Sillyness, Werd by Chris J. Davis is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License, unless otherwise noted.
Based on a work at chrisjdavis.org.