30 Day LOA

Step by step through learning the Law of Attraction

Jul 11th 2008
No Comments
respond
trackback
Del.icio.us (0)
Digg
StumbleUpon
Reddit

I love The Unstandard theme from 5thirtyone for it’s cool way of presenting posts, but the sidebar wasn’t down to be widgetised until the next release - and from his blog it seemed like the author might be too busy to do that for a while. So, not having done a lot of coding since the old days of html (although I did dabble a bit in php and javascript a few years back) I waded gamely in to learn my way around someone else’s - fantastic I might add - work. Hopefully without making too much of a hash of it.

The long and the short of it is, I found lots of sites on designing themes, and widgetizing ones that didn’t have it, but following most of them I found the neat pretty formatting of the sidebar suddenly disappeared in favour of a tiny, mashed up ultra small script. Argh! Not good! Today being the first day I’ve had any serious time to delve, though, I did discover the why and wherefore behind losing the formatting. It lies in the ‘functions.php’ page.

Credit where credit is due, as well as Wordpress.org stuff and a primer that got me started (and panicked when I lost the formatting), the turnkey point was when I found this post today that clarified it for me. When wordpress registers a sidebar, I needed to tell it what formatting to put before and after the titles, as well as before and after the widgets.

Now, I haven’t exactly got it right yet. For some reason it seems that each widget title appears larger than the one before it, so I’m not sure what’s going on there (update: found a workaround below, but still need some help with tidying it), but in a nutshell you need to do three things:

First: create or edit the functions.php file so that wordpress knows what to do if there are widgets on the sidebar. The code I got was from that last link above was:

<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>

Because the article explained that it was to fit in with custom headings etc, I knew where to look in the sidebar.php file to discover what needed to be put in for the Unstandard theme. My modified version is:

<?php
if ( function_exists(’register_sidebar’) )
register_sidebar(array(
‘before_widget’ => ‘<br /><br />’,
‘after_widget’ => ”,
‘before_title’ => ‘</ul><h3>’,
‘after_title’ => ‘</h3><ul class=”sidebar-ul”>’,
));
?>

The top bit ‘before widget’ gives you the nice spacing, the before and after title lines put it into the sidebar formatting. The list formatting didn’t come up until I added in the <ul class…> bit, but I suspect that’s where my enlarging titles are (were) coming from, since I couldn’t figure out how to close off the ul class. Don’t forget to save the changes before you move away from that page. The button’s way down the bottom (update file) so I for one keep forgetting to do it!

Update: I tested putting /ul in the ‘before title’ part, and it did fix the enlarging titles problem, but it’s messy, since the first widget will have a /ul that has no corresponding ul tag. Any flash coders out there know how to put conditions in there so it’ll only put the h3 on for the first widget?

Anyway, that’s step one. Now your theme knows how to handle widgets in the sidebar.

Step 2 is to tell the sidebar file that it’s supposed to allow widgets in. That involves two pieces of code - a start one and an end one, which you put in at the part you want to have the widgets come up instead of.

I wanted to keep the search bar, as well as that cool ‘next/previous’ thing, so I made sure to put it underneath that - the lines to look for are:

<h3>Explore Recent</h3>
<ul class=”sidebar-nextprev fix”>
<li class=”previous”><?php previous_post_link(’%link’) ?></li>
<li class=”next”><?php next_post_link(’%link’) ?></li>
</ul>
<?php } ?>

It had to go in AFTER the section got closed off with the } bit (got some weird errors when I accidentally put it in after the /ul instead.) Then I pasted in:

<?php if ( !function_exists(’dynamic_sidebar’)
|| !dynamic_sidebar() ) : ?>

Finally, I had to tell the file where it was supposed to stop putting in the dynamic stuff. That line is

<?php endif; ?>

and I put it in just before the last </ul> (on the last line). If you just want to copy & paste the whole lot into your sidebar, click here to open the text file with the entire code for your sidebar.php under your theme editor. Again, make sure you save the changes.

Final step is to go to your widgets tab under design and drag in the widgets you want. Remember this is replacing all the ones that come standard (recent posts, archive & meta) so if you want them, you’ll need to drag them over to the right to put them back on. It’s a good idea to click on ‘edit’ for each of them to check for any titles etc that are needed by the widgetised versions of the sidebar section.

That should be it. Open the site up in a new tab or window and hit refresh to check what it looks like, and start playing!

PS I also figured out how to tweak it so that I could pick what posts were displayed on the front page.  Comment back if you’d be interested in how to do that one too (it’s surprisingly simple…)

Share and Enjoy:
  • StumbleUpon
  • TwitThis
  • Digg
  • del.icio.us
  • Reddit
  • Technorati
  • Fleck
  • Slashdot
  • NewsVine
  • De.lirio.us
  • BlogMemes
  • Furl
  • ThisNext
  • Google
  • Spurl
  • co.mments
  • MyShare
  • Pownce
  • Smarking
  • BlinkList
  • Internetmedia
  • LinkaGoGo
  • Blue Dot
  • Netvouz
  • feedmelinks
  • YahooMyWeb
  • Linkter
  • Wists
  • Taggly
  • description
  • Facebook
  • Fark
  • Netscape
  • RawSugar
  • Scoopeo
  • description
  • SphereIt
  • blogmarks
  • blinkbits

Technorati Tags: , , , , , ,


This post is tagged , , , , , ,

No Comments

Leave a Reply