
In my previous post, I decided I would share my rough methodology on how I went about sprucing up my search widget in WordPress. If you’re just tuning in, here’s a quick update on what I described in The Making of a Not-So-Boring Search/RSS Widget:
- We downloaded some cool Photoshop brushes featured in Smashing Magazine, and used one of those to give a torn paper background to the search widget
- We took that background and prepped it for use from Photoshop, making minor modifications to include background transparency.
- We then modified the HTML for the search widget to accommodate the background styling.
- Finally, we added some simple CSS to pull in the background images.
Awesome. But what about the nasty, plain text links below the search area for the post and comment RSS feeds? Icky. Bland. Boring.
A Different Approach
Why do these links need to take up so much space? There’s no reason that we can’t compact them down into a single RSS button placed somewhere on the page, but I want to give my readers the ability to subscribe to both the posts and the comments…so we’re at a bit of a dilemma. But wait! Why can’t we roll these into a hidden section of the page that is easily accessible? A lot of sites do have that single button RSS link; this one will just have a special surprise.
Basically, the idea is to do this:

Making The Wrapping
Creating the images is just as easy if not easier than the images for the search background. I used the Rounded Rectangle Tool in Photoshop and then simple used the Pen Tool and the Direct Selection Tool to add some extra points for the tab curve and tweak the curve outward, respectively.

Once I have the shape the way I want it, I add a gradient across the surface in RSS-ish colors. I add some text and a little RSS icon, and the tab is done. Then, all I need to do is turn off the background, crop it to just the tab portion (including the curve on the far left), and Save For Web.

That takes care of the tab, but we still need to save the background for when the tab is extended upward. That’s as easy as saving a 1px high strip from the extended background like so:

Note: the icons I’m using for the RSS links are adaptations from the Silk set found at FamFamFam. I’ve modified these separately and uploaded them.
Preparing The Box
Now that we’ve cropped out the images we need and uploaded them, it’s time to look at some code. As with the search box, it’s pretty basic. The following is placed in the sidebar.php file for my WordPress theme, right above the code for the search section:
<div id="rss"><a class="tab">RSS</a><div id="rss_feeds" class="clearfix"><a id="rss_comments" href="<?php bloginfo('comments_rss2_url'); ?>" title="Comments Feed">Comments</a><a id="rss_posts" href="<?php bloginfo('rss2_url'); ?>" title="RSS Feed">Posts</a></div></div>
Nothing scary there. Just some organizational <div> tags and some WordPress function calls to specific RSS link locations (which can be found in their Codex). I’m using the <a class="tab">RSS</a> tag to serve as the point of interaction where the reader will click to expand/contract the RSS section. And now for the CSS wrapping paper:
/* RSS Feeds */#rss {background: url(../images/bkgrd_rss_top.png) no-repeat;margin: 10px 0 0 0;}#rss a {display: block;padding: 0;}#rss .tab {height: 20px;margin: 0 0 0 119px;width: 68px;}#rss #rss_feeds {background: url(../images/bkgrd_rss.png) repeat-y;display: none;padding: 3px 10px 3px 6px;}#rss_feeds a {float: right;padding: 2px 20px 2px 0;}#rss_feeds #rss_posts {background: url(../images/ico_rss_post.png) no-repeat center right;}#rss_feeds #rss_comments {background: url(../images/ico_rss_comment.png) no-repeat center right;margin: 0 0 0 14px;}
Nothing too fancy, but a brief explanation will help:
#rssproduces the background image of the tab, telling it not to repeat. This will sit behind the<a class="tab">RSS</a>.#rss aforces all<a>tags to display in block format, which allows margin and padding properties to be applied to them.#rss .tabsets the<a class="tab">RSS</a>to have a height matching the height of the tab background. It also sets a margin and width, making it act as a box over the tab on the right side, instead of a block clickable area across the top of the entire RSS section.#rss #rss_feedssets the 1px background to tile and fill in the space occupied by the RSS links. We set it to hide by default with the display:none property.#rss_feeds afloats the RSS links, allowing them to still have block properties applied to them while displaying inline next to each other.#rss_feeds #rss_postsand#rss_feeds #rss_commentsset the background icon images for the post and comments feed links, respectively.
All that give us the finished visual product. But how do we make it expand and collapse all nifty-like?
Enter jQuery
JQuery is a fantastic javascript library that makes visual effects extremely easy to achieve. It also does a lot more, like AJAX, but we’re just using the visual portion for this. Here’s what you need:
You can customize the UI core file if you want to keep the filesize low. All we’ll be working with is the Blind effect, so you can build your own UI JS file to include just that. All I need do is link these files in the head section of my WordPress theme by writing:
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.2.6.js"></script><script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-ui-1.5.2.js"></script>
Now, I’ve made a separate JS file called functions.js where I store all my global javascript functions that are used throughout the site. I’ve linked this in the theme and I’ll take the following code and place it in there:
$(document).ready(function() {//Function to hide/show RSS feeds tab and disable button unless JS is active$('#rss_feeds').hide();$('a.tab').click(function(){$('#rss_feeds').toggle("blind", { direction: "vertical" }, 250);});});
In English this means that once the document is ready ($(document).ready(function()), make sure that the <div id="rss_feeds"> is hidden. Once that’s done, setup a function so that when the <a class="tab"> is clicked, jQuery will toggle the <div id="rss_feeds"> using the Blind visual effect of the jQuery UI.
That’s really it. It’s not very complicated at all, and it adds a nice little visual effect. The best part is, should javascript be disabled, the RSS tab will default to being open so that the reader doesn’t miss out on the easy access to the RSS links.
In the future, I’ll look for more little things that can be done to tidy up a site and add an extra little personality to it. Except to read about them here when I do.


