Dynamically expanding single-post sidebar

Yay, I’ve now managed to do something I always wanted for my site. It always bothered me that when I wrote a lengthy blogpost, the right side of the screen always stayed empty when you scrolled down. Unfortunately I did not want to just chuck a few random items to expand it as it would mean that even when I wrote a short post, the sidebar would draw the post down which would have the unfortunate results of making the reader scroll down too much to read the comments (as well as look ugly)

After I used the FSD Sidebar I thought to myself that I really should find a solution to my dilemma. Initially I though to use different post templates and then just select one depending on how lengthy the post came out. Unfortunately, after I created the first, I discovered that WP does not support different templates for posts but only for pages. Unfortunately I could not find a plugin to activate this functionality. This was a bit unfortunate but I didn’t give up.

I went for my second idea: To have the single-post sidebar expand downwards with more items depending on the word count of the current post. I looked around the documentation for a way to collect the word count of a post but nothing was built in WP. Fortunately a short Googling led me to the page of someone who created a plugin exactly for this reason. Perfect!

Now I only needed to figure out how to use a php statement so that the sidebar does this expansion. Unfortunately since I don’t have any php skills to speak of, I turned to the nets again and fortunately it was easy to find what I needed. Unfortunately this statement does not accept an actual sidebar item within the brackets {} but a quick look at other themes informed me to the use of <?php if() ?> and <?php endif(); ?> statement. I still don’t know exactly how to use it properly but I did manage to make it work for me so all’s well.

All in all what I did is test if the wordcount is over a specific limit and then insert the item between the if and endif. Use four of these statements for increasing wordcounts, and your sidebar will expand only when you write an appropriate number of words. Of course this doesn’t take into account pictures or videos, or even different screen resolution that might change the size , but I don’t know if there is a way to test this unless I start checking their resolution each time and changing the word count needed…hmmm…

Ack no!

FSDaily Sidebar

It was proposed to me by a member of FSDaily to add their new sidebar to my site. Apparently a few of my posts have hit their front page and that drew their attention 🙂

In case you don’t know what FSDaily is, it’s a nice digg-clone which focuses on free software issues. A good alternative since now that digg is heavily sponsored by Microsoft there are fears of conflict of interests (and also digg has become way-way to popular imho).

So I said, why the hell not and dived in. I didn’t want to put it in my horizontal sidebars above and below but thought that this might be the perfect candidate to fill up my empty sidebar on single posts. Unfortunately the way the theme is formatted, it means that when I write something long, there is nothing to see on the left other than the initial information above. I was thinking of a way to fill this and as luck would have it, I got this proposal.

I think I will create special page template that I will use for short posts and in there I will not put anything in the sidebar. However on longer posts it would be worth filling that lonely and empty part with something. Perhaps I should diversify even more and create different page templates for different content. For example, on pages where I talk about religion, I could put the atheist blogroll, and on the ones I talk about Free Software, I can have the FSD along with other related stuff.

Still, I will need to ponder on this. The best thing to do would be to widgetize my single-post sidebar and have it easily updated. I just need to figure out how to widgetize.

Oh, well. Tell me what you think 😉

PS: It is ironic that, had I left this post in the original version, you would not not able to see the sidebar on this page. This is because I’ve recently modified my theme (I’ll write about it later) to dynamically expand the sidebar items depending on the word count of the current post. Unfortunately since this was a really short post and in order to see the FSD item you need at least 400 words, it stayed invisible. My solution? Write this post script 😉 . As a matter of fact, I needed a post script with at least a 100 extra words which easily makes this the largest one I’ve ever written 😀