№ 125. How to get the same style for default and widgeted sidebars

This is the easiest trick in the book. Unfortunately, theme authors don’t always pay attention to such minor details, and it comes to you to solve the problems of a design that doesn’t look exactly like the demo site. So, to help you fix such issues, I compiled a reference list on WordPress generated ids and classes for the sidebar widgets.

Retrieve the widgets’ markup

First of all, you need to know that the widgets’ markup is generated by WordPress (and not by the theme you use). This means you’ll have to provide the widgets’ ids and classes with the same styles as the default sidebars’ elements.

widget markup referenceNow lets take a closer look at the widgets’ markup. We can either check the WorPress generated classes in the Codex (which though is not recommended, as the list is incomplete), or we can use a test blog, add to the sidebar all the widgets available and check the page source. We’ll see something like this:

<form id="searchform" action="/index.php" method="get">
<input id="s" name="s" size="20" type="text" />
<input id="searchsubmit" type="submit" value="Go" />
</form></li>
<!–PAGES WIDGET–>
        <li id="pages" class="widget widget_pages">
<h2 class="widgettitle">Pages</h2>
<ul>
        <li class="page_item page-item-x"><a></a></li>
</ul>
</li>
<!–CATEGORIES WIDGET–>
        <li id="categories-x" class="widget widget_categories">
<h2 class="widgettitle">Categories</h2>
<ul>
        <li class="cat-item cat-item-y"><a></a></li>
</ul>
</li>
<!–RECENT POSTS WIDGET–>
        <li id="recent-posts" class="widget widget_recent_entries">
<h2 class="widgettitle">Recent Posts</h2>
<ul>
        <li><a></a></li>
</ul>
</li>
<!–RECENT COMMENTS WIDGET–>
        <li id="recent-comments" class="widget widget_recent_comments">
<h2 class="widgettitle">Recent comments</h2>
<ul id="recentcomments">
        <li class="recentcomments">p on <a href="/21/comment-page-1#comment-124">P</a></li>
</ul>
</li>
<!–ARCHIVES WIDGET–>
        <li id="archives" class="widget widget_archive">
<h2 class="widgettitle">Archives</h2>
<ul>
        <li><a>December 2007</a></li>
</ul>
</li>
<!–BLOGROLL WIDGET–>
        <li id="linkcat-2" class="widget widget_links">
<h2 class="widgettitle">Blogroll</h2>
<ul class="xoxo blogroll">
        <li><a></a></li>
</ul>
</li>
<!–TAG CLOUD WIDGET–>
        <li id="tag_cloud" class="widget widget_tag_cloud">
<h2 class="widgettitle">Tags</h2>
</li>
<!–META WIDGET–>
        <li id="meta" class="widget widget_meta">
<h2 class="widgettitle">Meta</h2>
<ul>
        <li><a>Site Admin</a></li>
</ul>
</li>
<!–TEXT WIDGET–>
        <li id="text-x" class="widget widget_text">
<h2 class="widgettitle">Text</h2>
<div class="textwidget">Some text</div></li>
<!–RSS WIDGET–>
        <li id="rss-somenumber" class="widget widget_rss">
<h2 class="widgettitle">
<a class="rsswidget" title="Syndicate this content" href="http://feeds2.feedburner.com/TheThemeMuseum">
<img style="background:orange;color:white;border:none;" src="/wp-includes/images/rss.png" alt="RSS" width="14" height="14" /></a> <a class="rsswidget" title="Your WordPress blog themes are here" href="http://wp-content-themes.com">Theme Museum Feed</a></h2>
<ul>
        <li>
<a class="rsswidget"></a></li>
</ul>
</li>
<!–CALENDAR WIDGET–>
        <li id="calendar" class="widget widget_calendar">
<h2 class="widgettitle"></h2>
<div id="calendar_wrap">
<table id="wp-calendar" border="0" summary="Calendar"><caption>month</caption>
<thead>
<tr>
<th title="Monday" scope="col">M</th>
</tr>
</thead>
<tfoot>
<tr>
<td id="prev" colspan="3"><a title="View posts for December 2007">« month</a></td>
<td class="pad"></td>
<td id="next" class="pad" colspan="3"></td>
</tr>
</tfoot>
<tbody>
<tr>
<td class="pad" colspan="6"></td>
<td>1</td>
</tr>
<tr></tr>
<tr>
<td>30</td>
<td>31</td>
<td class="pad" colspan="5"></td>
</tr>
</tbody></table>
</div></li>
<!–AKISMET WIDGET–>
        <li id="akismet" class="widget widget_akismet">
<h2 class="widgettitle">Spam Blocked</h2>
<div id="akismetwrap">
<div id="akismetstats">
<a id="aka" href="http://akismet.com">
<div id="akismet1"><span id="akismetcount">867</span><span id="akismetsc">spam comments</span></div>
<div id="akismet2"><span id="akismetbb">blocked by</span>
<span id="akismeta">Akismet</span></div>
</a></div>
</div></li>
 

The style
The next step is styling the ids and classes we discovered in the XHTML.

.widget{} /* use it to style all the widgets the same way */
h2 .widgettitle{}

#search{}
.widget_search{}
form #searchform{} /* pay attention to the default/reseted form styles */
input #s{}
input #searchsubmit{}

#pages{}
.widget_pages{}
.widget_pages ul{}
.widget_pages ul li{}
.widget_pages ul li a{}
.page_item {}
.page-item-x{}  /* replace x with the actual page ids */

#categories-x{} /* replace x with the number assigned by WordPress; you can find it in the page source */
.widget_categories{}
.cat-item{}
.cat-item a{}
.cat-item-y{} /* replace x with the actual cat ids */
.cat-item-y a{}

#recent-posts{}
.widget_recent_entries{}
.widget_recent_entries ul{}
.widget_recent_entries ul li{}
.widget_recent_entries ul li a{}

#recent-comments{}
.widget_recent_comments{}
ul #recentcomments{}
li .recentcomments{}
.recentcomments a{}

#archives{}
.widget_archive{}
.widget_archive ul{}
.widget_archive ul li{}
.widget_archive ul li a{}

#linkcat-x /* replace x with the actual blogroll cat id; you’ll find it in the page source */
.widget_links{}
ul .xoxo{}
ul .blogroll{}
.xoxo li{}
.xoxo li a{}
.blogroll li{}
.blogroll li a{}

#tag_cloud{}
.widget_tag_cloud{}
.widget_tag_cloud a{}

#meta{}
.widget_meta{}
.widget_meta ul{}
.widget_meta ul li{}
.widget_meta ul li a{}

#text-x{} /* replace x with the actual widget id you see in the page source */
.widget_text{}
div .textwidget{}

#rss-x{} /* replace x with the id assigned by WordPress */
.widget_rss{}
a .rsswidget{}

#calendar{}
.widget_calendar{}
#calendar_wrap{}
table #wp-calendar{} /* pay attention to the default/reseted table styles */
table #wp-calendar abbr{} /* pay attention to the default/reseted abbr styles */
table #wp-calendar td .pad{}

/* The default style for the Akismet widget (nested by WordPress inside the  tag */

#aka,#aka:link,#aka:hover,#aka:visited,#aka:active{color:#fff;text-decoration:none}
#aka:hover{border:none;text-decoration:none}
#aka:hover #akismet1{display:none}
#aka:hover #akismet2,#akismet1{display:block}
#akismet2{display:none;padding-top:2px}
#akismeta{font-size:16px;font-weight:bold;line-height:18px;text-decoration:none}
#akismetcount{display:block;font:15px Verdana,Arial,Sans-Serif;font-weight:bold;text-decoration:none}
#akismetwrap #akismetstats{background:url(/wp-content/plugins/akismet/akismet.gif) no-repeat top left;border:none;color:#fff;font:11px ‘Trebuchet MS’,‘Myriad Pro’,sans-serif;height:40px;line-height:100%;overflow:hidden;padding:8px 0 0;text-align:center;width:120px}

Now identify the styles for the default sidebars elements and add the WordPress generated ids and classes in the style.css file (don’t forget to separate them with a comma). For instance

#sidebar ul li,.widget{}
#sidebar h3,h2 .widgettitle{}
/* etc */

As simple as that.

Tags: , ,

Published on the 23rd of March, 2009, in WordPress · Print

2 Comments on “How to get the same style for default and widgeted sidebars”

  1. Just putting together my first WordPress project in years, and my how things have changed! Thanks for this post – what a great tool!

    (Splattastic! will, Lord willing, be live tomorrow)

    Cheers

  2. Thank you so much! These pointers were very helpful—I was trying to edit the meta widget styles.

Some Pings and Trackbacks Are Welcome

Leave a Reply

Recent comments

Colophon

This website was made by Delicia, who is deeply in love with WordPress. It is built on a 30x20px module, with Georgia and Helvetica/Arial. The design is the result of many years she spent reading Wittgenstein.