{"id":55,"date":"2008-07-11T09:15:07","date_gmt":"2008-07-11T09:15:07","guid":{"rendered":"http:\/\/30dayloa.com\/?p=55"},"modified":"2008-07-11T12:03:01","modified_gmt":"2008-07-11T12:03:01","slug":"widgetizing-the-unstandard-theme-sidebar","status":"publish","type":"post","link":"https:\/\/30dayloa.com\/blog\/widgetizing-the-unstandard-theme-sidebar\/","title":{"rendered":"Widgetizing the Unstandard Theme sidebar"},"content":{"rendered":"<p>I love <a href=\"http:\/\/5thirtyone.com\/the-unstandard\">The Unstandard theme<\/a> from 5thirtyone for it&#8217;s cool way of presenting posts, but the sidebar wasn&#8217;t down to be widgetised until the next release &#8211; 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&#8217;s &#8211; fantastic I might add &#8211; work.  Hopefully without making too much of a hash of it.<\/p>\n<p>The long and the short of it is, I found lots of sites on designing themes, and widgetizing ones that didn&#8217;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&#8217;ve had any serious time to delve, though, I did discover the why and wherefore behind losing the formatting.  It lies in the &#8216;functions.php&#8217; page.<\/p>\n<p>Credit where credit is due, as well as WordPress.org stuff and <a href=\"http:\/\/automattic.com\/code\/widgets\/themes\/\" target=\"_blank\">a primer that got me started<\/a> (and panicked when I lost the formatting), the turnkey point was when I found <a href=\"http:\/\/www.quickonlinetips.com\/archives\/2007\/11\/how-to-widget-enable-wordpress-themes-in-3-easy-steps\/\" target=\"_blank\">this post<\/a> 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.<\/p>\n<p>Now, I haven&#8217;t exactly got it right yet.  For some reason it seems that each widget title appears larger than the one before it, so I&#8217;m not sure what&#8217;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:<\/p>\n<p>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:<\/p>\n<blockquote><p><code>&lt;?php<br \/>\nif ( function_exists('register_sidebar') )<br \/>\nregister_sidebar(array(<br \/>\n'before_widget' =&gt; '',<br \/>\n'after_widget' =&gt; '',<br \/>\n'before_title' =&gt; '&lt;h4&gt;',<br \/>\n'after_title' =&gt; '&lt;\/h4&gt;',<br \/>\n));<br \/>\n?&gt;<\/code><\/p><\/blockquote>\n<p>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:<\/p>\n<blockquote><p>&lt;?php<br \/>\nif ( function_exists(&#8216;register_sidebar&#8217;) )<br \/>\nregister_sidebar(array(<br \/>\n&#8216;before_widget&#8217; =&gt; &#8216;&lt;br \/&gt;&lt;br \/&gt;&#8217;,<br \/>\n&#8216;after_widget&#8217; =&gt; &#8221;,<br \/>\n&#8216;before_title&#8217; =&gt; &#8216;&lt;\/ul&gt;&lt;h3&gt;&#8217;,<br \/>\n&#8216;after_title&#8217; =&gt; &#8216;&lt;\/h3&gt;&lt;ul class=&#8221;sidebar-ul&#8221;&gt;&#8217;,<br \/>\n));<br \/>\n?&gt;<\/p><\/blockquote>\n<p>The top bit &#8216;before widget&#8217; gives you the nice spacing, the before and after title lines put it into the sidebar formatting.  The list formatting didn&#8217;t come up until I added in the &lt;ul class&#8230;&gt; bit, but I suspect that&#8217;s where my enlarging titles are (were) coming from, since I couldn&#8217;t figure out how to close off the ul class. Don&#8217;t forget to save the changes before you move away from that page.  The button&#8217;s way down the bottom (update file) so I for one keep forgetting to do it! <span style=\"color: #ff0000;\"><strong><\/strong><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><strong>Update<\/strong><\/span>: I tested putting \/ul in the &#8216;before title&#8217; part, and it did fix the enlarging titles problem, but it&#8217;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&#8217;ll only put the h3 on for the first widget?<\/p>\n<p>Anyway, that&#8217;s step one.  Now your theme knows how to handle widgets in the sidebar.<\/p>\n<p>Step 2 is to tell the sidebar file that it&#8217;s supposed to allow widgets in.  That involves two pieces of code &#8211; a start one and an end one, which you put in at the part you want to have the widgets come up instead of.<\/p>\n<p>I wanted to keep the search bar, as well as that cool &#8216;next\/previous&#8217; thing, so I made sure to put it underneath that &#8211; the lines to look for are:<\/p>\n<blockquote><p>&lt;h3&gt;Explore Recent&lt;\/h3&gt;<br \/>\n&lt;ul class=&#8221;sidebar-nextprev fix&#8221;&gt;<br \/>\n&lt;li class=&#8221;previous&#8221;&gt;&lt;?php previous_post_link(&#8216;%link&#8217;) ?&gt;&lt;\/li&gt;<br \/>\n&lt;li class=&#8221;next&#8221;&gt;&lt;?php next_post_link(&#8216;%link&#8217;) ?&gt;&lt;\/li&gt;<br \/>\n&lt;\/ul&gt;<br \/>\n&lt;?php } ?&gt;<\/p><\/blockquote>\n<p>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:<\/p>\n<blockquote><p>&lt;?php if ( !function_exists(&#8216;dynamic_sidebar&#8217;)<br \/>\n|| !dynamic_sidebar() ) : ?&gt;<\/p><\/blockquote>\n<p>Finally, I had to tell the file where it was supposed to stop putting in the dynamic stuff.  That line is<\/p>\n<blockquote><p>&lt;?php endif; ?&gt;<\/p><\/blockquote>\n<p>and I put it in just before the last &lt;\/ul&gt; (on the last line).  If you just want to copy &amp; paste the whole lot into your sidebar, <a href=\"http:\/\/30dayloa.com\/files\/sidebar.txt\" target=\"_blank\">click here<\/a> to open the text file with the entire code for your sidebar.php under your theme editor.  Again, make sure you save the changes.<\/p>\n<p>Final step is to go to your widgets tab under design and drag in the widgets you want.  Remember this is <em>replacing<\/em> all the ones that come standard (recent posts, archive &amp; meta) so if you want them, you&#8217;ll need to drag them over to the right to put them back on.  It&#8217;s a good idea to click on &#8216;edit&#8217; for each of them to check for any titles etc that are needed by the widgetised versions of the sidebar section.<\/p>\n<p>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!<\/p>\n<p>PS I also figured out how to tweak it so that I could pick what posts were displayed on the front page.\u00a0 Comment back if you&#8217;d be interested in how to do that one too (it&#8217;s surprisingly simple&#8230;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I love The Unstandard theme from 5thirtyone for it&#8217;s cool way of presenting posts, but the sidebar wasn&#8217;t down to be widgetised until the next release &#8211; 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,60],"tags":[66,65,64,67,63,62,61],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-featured","category-web-design","tag-customizing","tag-scripting","tag-sidebarphp","tag-the-unstandard","tag-widgetising","tag-widgetizing","tag-wordpress-theme"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":1,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/posts\/55\/revisions\/153"}],"wp:attachment":[{"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/30dayloa.com\/blog\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}