WordPress Sidebar Widget Sandwich

This tutorial will cover adding several “sidebars” to sidebar.php using simple “if” statements, and where to place unwidgeted content in the same file. This is a first step to my next tutorial, which will present some ideas for how to style a wide, widgetized sidebar.

Mixing widgetized and unwidgetized sidebar content can be confusing. Once in a while there is a script or a plugin that is not available as a sidebar widget, or a widget that is a hassle to reproduce as unwidgetized code. Sandwiching a few widgets between unwidgetized content lets you use both flavors as needed.

  1. Step One: Add more sidebars to functions.php
  2. Step Two: Add extra “sidebars” to sidebar.php
  3. Step Three: Understand where to put unwidgetized content

Step One: Add more sidebars to functions.php

Adding the example code below to functions.php allows for three “sidebars.” The code to add a sidebar to funtions.php is the same if a sidebar is an include or if it is called by an “if” statement as in my example sidebar.php contents in step two. To help with styling later, have used an array that adds an ID and class named for each widget used.

The number in the register_sidebars line is equal to the number of sidebars that will show up at Presentation > Widgets. Dragging widgets into those sidebars won’t have any effect unless each specific sidebar also appears somewhere in your template.

 

if ( function_exists('register_sidebar') ){
  register_sidebars(3,array(

    'before_widget' => '
<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>
 

',
    'before_title' => '
<h2 class="widgettitle">',
    'after_title' => '</h2>

 
',
  ));
}
 

I like to add an extra “sidebar” or two to sidebar.php, when I am first setting up a theme. This gives me flexibility down the line. If the building blocks are already in place, I won’t have to re-think anything if I later need to mix widgeted and unwidgeted content. Note that additional “sidebars” won’t show up in Presentation > Widgets unless there is corresponding code in funtions.php.

Using an “if” statement means that “sidebars” without active widgets won’t show up in the generated page, unless there is alternative code before the php endif of that “sidebar” – see “Heading” under !dynamic_sidebar(1) below.

If widgets are active for a “sidebar,” alternative content before the php endif of that sidebar won’t show. That makes for a handy place to leave myself notes that I don’t want to show in the generated page.

Though !dynamic_sidebar() gives the the same result as !dynamic_sidebar(1), once I have more than one sidebar I like to add the “1” to help me remember that there are more than one of them.

Example content for a sidebar.php file:

 
<div id="sidebar">

<ul>
 
   <?php /* Widgetized sidebar. */
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(1) ) : ?>

<li>
<h2>Heading</h2>
<ul>
<li>list item</li>
<li>list item</li>
</ul>

</li>
 
   <?php endif; ?>
 
   <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(2) ) : ?>

   <?php endif; ?>
 
   <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(3) ) : ?>

   <?php endif; ?>
</ul>
</div>
 

Step Three: Understand where to put unwidgetized content

Still in sidebar.php, find the start and end of each “if” statement. You don’t have to know what an “if” statement is, or how to write one. All that’s needed is to learn to recognize where they start and end.

These “if” statements say are that “if” there is a “dynamic_sidebar” then widgets active in whichever numbered “!dynamic_sidebar” should be used, followed by closing the “if” statement with an “endif.” A “sidebar” with active widgets will only show widgets. Unwidgeted content between a pair of “if” and “endif” will only show when the “sidebar” referred to by that particular “if” statement has no active widgets. So, basically, unwidgetized content needs to go before the “if” and after the “endif.”

In the illustration below, I placed “This line…” in between list item tags because standard widgets will generate navigation lists. When setting something up, formatting notes to myself using (x)html that will coordinate with the with the rest of that area helps me to stay organized.

Another look at sidebar.php:

 
<div id="sidebar">
<ul>
<li>This line will show, regardless.</li>

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

<li>This line will NOT show when the first sidebar has active widgets</li>
 
   <?php endif; ?>
<li>This line will show, regardless.</li>
 

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

<li>This line will NOT show when the second sidebar has active widgets</li>
 
   <?php endif; ?>
<li>This line will show, regardless.</li>
</ul>

</div>
 

Quick! Break My Tie

Yowzers! Is this doldrums or the reverse?

I have four half-finished drafts that I like just about equally. Help me pick which one to finish first.

First comment gets it.

  • A WordPress tutorial
  • Thoughts about building an audience when traffic isn’t the primary goal
  • Some semi irreverent ramblings
  • An “I have a crush on” post – stuff I’ve seen and liked recently

DazzlinDonna on Community – an Interview

In mid January I asked readers to tell me what they want to see more of in this blog. I offered to interview whoever’s idea made me “the happiest and most interested.” Donna Fontenot of DazzlinDonna commented that she’d like to see me expound on my tag line, “Using the Internet to Build Community.”

Bingo and bravo. Community is the topic, and I can’t think of anyone I’d rather interview about community.

Elizabeth: Donna, do you remember the first time you made a connection between that thing called “computer” and the concept of community? Describe it for us?

Donna: The first time that I can remember (which may be different than the first time) was in 1989, I think, when I first logged on to the Internet via Prodigy. Actually, I’m not sure you could even call it the Internet, since Prodigy was a closed garden, but the details don’t matter. What matters is that I could communicate in all sorts of ways with people I didn’t know and my world suddenly became large.

Elizabeth: What is the most fun you’ve ever had online with other people?

Donna: I’m a programming geek at heart, so “fun” might not be the same for me as it is for others. But I think the most fun I’ve had online was at the beginning of two different periods of my career. The first was when I first began programming in ColdFusion, and was actively involved in ColdFusion forums and user groups. We would program all through the night, and the interaction was intense but fun. The second was when I first began diving into SEO, and again, I became actively involved in search-related forums and projects. Arguing, discussing, testing, and debating the various possible search tactics and algorithm changes was tons of fun. Both involved “new learning” and “shared knowledge”, which would have been almost impossible without online communities.

Elizabeth: So, why is community such a big deal, anyway?

Donna: Elizabeth, I’ve been watching several sites (both mine and others) take on a life of their own simply because of “community”. Let me give you a really quick and easy example. One site I track uses the old “sign up and pay a monthly fee” monetization method. This site does absolutely zero advertising or marketing of any kind. A few people have found it via some really long-tail searches, but the vast majority of the site’s growth is simply because one person liked it and told another, and that person liked it and told a couple of others, etc. People actually pay a fair amount of money each and every month simply because the community has recommended it. And the best part is…the growth is occuring exponentially. Before, it was a few people telling a few people, and now it’s a LOT of people each telling a few people. What was once a tiny community is now a really BIG one. I couldn’t have created a better growth model than that of building a community.

Elizabeth: What are some differences between search traffic and community traffic?

Donna: If I could only choose one, I’d choose search traffic, simply because it tends to be more targeted. Someone was actively looking for what my site has to offer, so the chances of converting that person are fairly high (assuming the search engine didn’t mislead the user by presenting faulty search results).

Community traffic may or may not be so targeted, depending upon what type of community traffic it is. A person stumbling into my site (via StumbleUpon, for example) is more likely to be just randomly surfing for fun, and may not stick around for long. On the other hand, a user who was guided to my site by members of another community (we’re talking word of mouth recommendations here) could be extremely targeted and extremely convertable. The good thing is that we don’t have to choose just one. The broader the reach, the greater the chance of growth and success.

One thing to keep in mind. Despite the fact that social visitors (Digg traffic, etc.) are generally here one second, gone the next, those visitors do matter. A large segment of people are exposed to your site. You can’t be expected to connect with all of them, but it is your job to “hook” as many as you can. Be compelling. Be interesting. Be informative. Give them some reason to notice you. If you can manage that, you’ll find that enough of that traffic will return, or bookmark you, or tell someone else about you, or link to you. They may seem like driveby visitors, and in a sense they are, but if you’ve done your job well, they will eventually have an impact on your growth.

Elizabeth: Are there magic ingredients that make the difference between blogs that have comments enabled and blogs that feel like a community?

Donna: I think the magic lies with the blog author(s) and the relationship between the author(s) and the readers. An arrogant, self-serving blogger may find it a little more difficult to nurture a community, although he or she may end up with a lot of comments. It’s kind of like the difference between attending a mandatory office meeting, and hanging out at a friend’s house to watch a football game. Both may involve a lot of communication, but which one feels more like a community?

Elizabeth: Can subscription-based monetization methods succeed without a sense of community?

Donna: Yes, certainly they can, especially if one has enough money to market the site properly. But you may end up with a lot of churn, in which you are constantly having to spend money to attract new members, so that you can replace the ones who’ve canceled and left. That makes it harder to grow, as the new members are only replacing old members, and not adding more to the community.

But, I come from a background of having to succeed with less than $20 available, so creativity has to be involved. The best way to convince someone to part with their hard earned cash is to have someone they trust tell them to do so. If the community does the marketing for you, you can get by without a big budget. And if the community is recommending the site, then the community is probably happy with it. And happy community members stick around for a longer time, which reduces the amount of new members needed just to deal with churn.

Elizabeth: How difficult is it to build a community? Are there any obvious community killers?

Donna: I’ll be honest. It can be tough. There are lots of pitfalls along the way. There are always naysayers and trolls that live for the chance to cause dissension within a community. The best way to handle these problems is to have help. As the community starts to build, find a few loyal members who have the natural ability to lead and the temperament to smooth things over. Encourage them to help build the community and the job will become much easier. In a forum, these would be your moderators. In social networks, these might be the most popular users.

Elizabeth: Can Web 2.0 style communities help old, established 1.0 causes?

Donna: Funny you should mention that, Elizabeth. As you know, I’ve recently organized a charity event that does just that. In fact, this not only brings together the members of one community, but adds some real weight to the project by connecting several communities together – all meeting for a common goal – that of helping a worthy charity. It starts off with a bigger footprint because project members already have readerships of their own and enjoy communicating with the public. In fact, you may have noticed this big, big, (I’m talking HUGE) event has already begun. (Forgive the puns, but I can’t help myself).

Of course, I’m referring to the SEOsFightFat project, in which 11 SEOs got together to lose weight, and raise money for a worthy charity. Each of the SEOs has their own network of friends, co-workers, clients, and associates. Each of these networks is a community, and by bringing all of these communities together, we hope to reach a larger audience. Of course, we are hoping that many people in that audience will support us in our effort, both by cheering us on, and by pledging donations for the winning charity. With luck, we can connect communities with communities to not only help us lose weight, but bring in some BIG, FAT donations for a good cause. That’s what communities are all about…joining together to share common interests or to work towards a common goal. Sometimes that goal is to raise money for a charity, sometimes that goal is to create a successful web site. Whatever the goal is, community can help bring it about.

Going Pink

breast cancer awareness ribbonWhat a difference a few days can make. This time last week I was thinking about adding blogging for a cause as a regular feature. One thing led to another and pretty soon I was joking about dyeing my hair pink.

Do you need a little backstory? Yes, methinks you need a little backstory. Here goes.

Pink Valentine’s marketing frou frou brightening local stores led me to musing about the pink breast cancer awareness ribbon, which led to remembering that I haven’t gotten around to getting a mammogram lately, which for some strange reason led to musing about midlife crisis and how much fun the first bubble of midlife crisis was for yours truly (when I wasn’t suffering,) which reminded me of my 20’s for the same reason (fun, when I wasn’t suffering) which reminded me of how I used to joke that one year for a good enough reason (a “cause”) I’d dye my hair pink for Valentine’s day.

During about the same time period I heard about SEOs Fight Fat from Donna Fontenot, and I guess you could say that one thing led to another, which leads me to more backstory.

Sympathy Dieting Sucks

Since SEOs Fight Fat launched I’ve gained five pounds. My intent was to do a little tandem sympathy dieting and take my weight down another 25 lbs, at five pounds a month. Losing 25 lbs last year and 25 this year would get me down to a comfortable place. Another 25 and I’d be at my pre-baby weight of 21 years ago… but that’s not really necessary. At my height, nearly six feet tall, anything under 175 lbs is a matter of distribution, and I’m cool with that. However, going from 200lbs to 205 in one week was not in the plan.

Maybe sympathy needs a compass

Sympathy dieting is not the same as putting yourself on the line. Sympathy opens everything. In my case last week that included opening my mouth for veritable slabs of super yummy, skin-on lemon-pepper chicken – and for the most part I’m someone who lives happily on moderate amounts of nuts and berries and dairy. It’s just that I get almost zero exercise and a lot can happen between “moderate” and “amount” when I listen to a craving.

Cravings lie. Cravings say “You need to eat another heart-shaped frosted cake before bed time. Mmmmm, satisfying. Now you need another.”

Cravings should be used to fuel comfort, curiosity and the creative, but never to make decisions impacting health. Health is a choice – not even in the same universe as a craving.

Choosing health is a daily celebration of life

Not to get all fluffy about it, but dieting is not about the skinny jeans or the struggle to avoid one’s beloved cheese fries. My neighbor is a case in point.

He’s a tall, broad-shouldered guy who’s had a full life – military service, kids, work, friends, extended family, retirement, and his current position as Neighborhood Ambassador. The day I moved in he walked over and introduced himself. Very old school. Very home town friendly. Very… Cre8asite. Yes, I spend too much time online.

Anyhoo, my neighbor has lost more than 90 lbs over the course of a year. At the halfway point he got cancer and found that he is not a good surgery candidate because of what the weight does to his blood pressure. He did other treatment. He’s OK so far, and is still plugging away at the diet.

Makes you think, doesn’t it? You never know what will happen next. Weight loss is not about fitting into the skinny jeans. The skinny jeans are a side effect, a milepost. The better part of willpower is willingness to live the good life. Cheese fries ain’t got nothin’ on that.

Are You Willing to Get Wacky For a Cause?

I am. :)

Remember up top when I said something about pink hair and joking that one year for a good enough reason (a “cause”) I’d dye my hair pink for Valentine’s day? Here goes.

Some of the folks at SEOs Fight Fat are off to a slow start. Some haven’t started blogging yet, and some who have have yet to sell an ad on their page of the project. I want to encourage them to go a little crazy over their cause, by going a little crazy myself.

If each of the eleven SEOs at SEOs Fight Fat sell a new display ad by February 14th, I’ll dye my hair pink.

To be fair, Valentine’s Day is only six days away. If they want a re-match, I’ll go green for three new ads each by St. Patrick’s Day – March 17th. Do both and I’ll do both. Come close and make me an offer, but I’m not shaving anything.

DazzlinDonna, Jennifer Laycock, Aaron Wall, Jim Boykin, Simon Heseltine, Nathania Johnson, Ben Cook, Scottie Claiborne, Jeff Quipp, David Wallace and Debra Mastaler, li’l ol (tall) me is callin’ out you and your readership.

If you’re reading this and smiling I encourage you to leave me a tip. It will cost a mere dollar to add a message to the brand new My Top Spots gizmo in my side bar. I think it’d be a lot of fun if my first few tips come from people who would like to see their choice of the SEOs Fight Fat bunch dye their own hair. I encourage you to click “Show some love, buy one” and plunk down $1 to leave an encouraging, linked message for the SEO of your choice.

Oh, and for your information, my long hair is now a natural brown, and I’ve got an appointment for that mammogram.

WordPress Urgent Upgrade

Two days ago WordPress announced an urgent security update.

WordPress 2.3.3 is an urgent security release. If you have registration enabled a flaw was found in the XML-RPC implementation such that a specially crafted request would allow a user to edit posts of other users on that blog. In addition to fixing this security flaw, 2.3.3 fixes a few minor bugs. If you are interested only in the security fix, download the fixed version of xmlrpc.php and copy it over your existing xmlrpc.php. Otherwise, you can get the entire release here.

Also, there is a vulnerability in the WP-Forum plugin that is being actively exploited right now. If you are using this plugin, please remove it until an update is available from its author.

Since we are talking security, remember to use strong passwords and change them regularly. While you’re updating WP and your plugins, consider refreshing your passwords.

From WordPress

Don’t you just love YouTube? I found this after searching for “wordpress upgrade.”

Upgrade Advice

Deactivate plugins before upgrading WordPress. Usually, even if you forget to deactivate plugins everything will be OK. However, once in a while a plugin will conflict with an upgrade, and reactivating them one by one will help indicate the culprit.

My opinion is that it is better to drop a plugin than put off a security upgrade. Plugin authors who are actively maintaining their plugin are usually pretty good about speedy updates.

Protect customization. If you use a customized version of WordPress Default or Classic, consider naming your version and moving it into a folder of its own. No matter how careful we all are, there will come a day when something important gets copied over. If your theme folder is not part of a standard WP install, there is no way that upgrading can accidentally copy over your work.

In case you’re interested, I wrote a brief guide about how to use WP Default to start a new theme.

Protecting Customizations to WordPress Default

So, it’s time to install an important security upgrade. You back up your database, but forget to back up your customized version of a theme that comes with WordPress. When performing the upgrade, the new Default files overwrite the old ones, and your work on WordPress Default is lost.

There are two lessons here. The really obvious one is to back up everything before doing anything, but you might also want to look giving that customized Default theme a new home.

How To Start a New Theme

It’s very simple. Very quick. Very easy.

Step One: Back up your theme

Now that there is a copy sitting on your computer, you’re free to play.

Step Two: Add a new theme name to style.css

Open style.css with a text editor. At the top there is a list of information, between comment tags. Every theme must include a style.css, and the top of style.css must provide details about the theme in the form of comments. Some lines are required, some are optional. No two installed themes should have the same Theme Name.

Here is an example credits block:

/*
Theme Name: Theme Name
Theme URI: the-theme's-homepage
Description: a-brief-description
Author: your-name
Author URI: your-URI
Template: use-this-to-define-a-parent-theme--optional
Version: a-number--optional
.
General comments/License Statement if any.
.
*/

WordPress uses “Theme Name” to identify each theme in Presentation > Themes. Spaces and punctuation are fine. If your theme name is J@ne’Z Custom GiZmo BiZ, your Theme Name line might look like this:

Theme Name: J@ne'Z Custom GiZmo BiZ

Feel free to add your own information to the rest of the credits. When building on top of someone else’s work, it’s good form to leave some of their credits in place, at the very least in the general comments area.

Step Three: A new folder for a new theme

Change the folder name to something that fits your version of the theme. Purist that I am, for J@ne’Z Custom GiZmo BiZ I’d probably use a folder name like jane-gizmo. IMHO folder names (“directories” for us nerdy types) are best left plain jane. Avoid spaces or punctuation, and stick with lower case. Instead of spaces, use hyphens. The directory names my-theme or mary-theme is better than the directory names my theme or Mary's Theme.

  1. Upload your newly named folder to /wp-content/themes/ along with the rest of the themes
  2. Open Presentation > Themes, and voila, you’ll see your new theme name with the original Default screenshot.

Step Four: Add a screen shot

A screen shot is a nice touch, though not essential: the theme will still work without it.

Replace the file original WP Default theme’s screenshot.png in your theme dolder with your own screen shot of the same name and file type. Common screen shot size ranges from 200px to 500px at the widest point. File size is usually between 10kb and 50kb, though they can be found at over 100kb.

Wide Sidebar and Header for WordPress Default Theme

This tutorial will walk you through how to widen Kubrick, the WordPress Default Theme, without losing the ability to use the theme’s custom header image coloring. The result will be wide enough for a second sidebar, or for one of the extra wide sidebars that are increasingly popular.

I added 200px to the WordPress Default theme’s header and sidebar, for a 390px sidebar with a total of 940px overall. Look around online and see what kind of width you like. I’ve seen multi-column sidebars anywhere from 300px to 500px wide.

These are copy and paste directions. Programming skills are not required – simply pay careful attention to details. You’ll need basic image editing skills, a text editor like notepad, and the ability to FTP your theme’s files.

  1. Step One: Change background image widths
  2. Step Two: Edit php that customizes image color
    • 2)a: Add 200px to the header image width variable
    • 2)b: Find code that defines header shape coordinates
  3. Step Three: Change style sheet to match new width
    • 3)a: Widen page container
    • 2)b: Increase width of header container
    • 3)c: Widen footer
    • 3)c: Widen sidebar or add a second sidebar

Step One: Change the header image width

Look in /wp-content/themes/default/images/ for the files named kubrickheader.jpg, kubrickfooter.jpg, kubrickbgwide.jpg, and kubrickbg-ltr.jpg or kubrickbg-rtl.jpg. Use an image editing program to increase the width of each by 200px.

Avoid changing the radius of the corners in kubrickheader.jpg by avoiding tools that change the scale of an image. Stick to copy and paste and you’ll be fine. The original header image is 760px wide and 200px high. Adding 200px will result in a finished image that is 960px wide and 200px high. If you want less height, take a look at Reducing Header Height – WordPress Default Theme.

In kubrickbg-ltr.jpg or kubrickbg-rtl.jpg add 200px width to the darker portion that forms a background for the sidebar. Blogs written in languages read from left to right only need kubrickbg-ltr.jpg. You won’t need kubrickbg-rtl.jpg unless blogging in a language that is written from right to left, such as Hebrew or Arabic.

Step Two: Edit php that customizes image color

This gets a little more complicated, but you really don’t need to know how to write the php that draws color customizations. Just find the parts to change, and change only those without adding or subtracting spaces or punctuation. You’ll be changing the code in three places.

Look in /wp-content/themes/default/images/ for the file named header-img.php and open it in a text editor. If you’re like I was the first time I opened it, you don’t know much php but do remember enough algebra to recognize graphing coordinates.

2)a: Add 200px to the header image width variable

Find where the height of the image is defined, and add 200px. The original width is 740px, not 760px, because the outside border is left white.

Change $x2 = 740 to $x2 = 940.

Original code:

 
// Blank out the blue thing
for ( $i = 0; $i < $h; $i++ ) {

   $x1 = 19;
   $x2 = 740;
 

After editing:

 
// Blank out the blue thing

for ( $i = 0; $i < $h; $i++ ) {

   $x1 = 19;
   $x2 = 940;
 

Add 200px to the width by changing $x2 = 739 to $x2 = 939.

Before editing:

// Draw a new color thing
for ( $i = 0; $i < $h; $i++ ) {

   $x1 = 20;
   $x2 = 739;
 

After editing:

// Draw a new color thing

for ( $i = 0; $i < $h; $i++ ) {

   $x1 = 20;
   $x2 = 939;
 

2)b: Find code that defines header shape coordinates

This is where remembering algebra made me curious about what would happen if I changed the coordinates. Widen the image 200px by adding 200 to the first number in the first five rows of numbers, and you’re through with this step.

Original code:

 
// Define the boundaries of the rounded edges ( y => array ( x1, x2 ) )
$corners = array(
   0 => array ( 25, 734 ),
   1 => array ( 23, 736 ),
   2 => array ( 22, 737 ),
   3 => array ( 21, 738 ),
   4 => array ( 21, 738 ),
   177 => array ( 21, 738 ),
   178 => array ( 21, 738 ),
   179 => array ( 22, 737 ),
   180 => array ( 23, 736 ),
   181 => array ( 25, 734 ),
   );

 

After editing:

 
// Define the boundaries of the rounded edges ( y => array ( x1, x2 ) )
$corners = array(
   0 => array ( 25, 934 ),
   1 => array ( 23, 936 ),
   2 => array ( 22, 937 ),
   3 => array ( 21, 938 ),
   4 => array ( 21, 938 ),
   177 => array ( 21, 938 ),
   178 => array ( 21, 938 ),
   179 => array ( 22, 937 ),
   180 => array ( 23, 936 ),
   181 => array ( 25, 934 ),
   );

 

Step Three: Change style sheet to match new widths

In the WordPress Default theme some divs and classes appear twice, because of the way the Michael Heilemann has separated structure and formatting. It’s OK to either leave them separate or combine them. To keep it simple here for beginners I’ve left them separate, like they are in the original style sheet.

Look for style.css at /wp-content/themes/default/style.css, and open it in a text editor. You’ll be changing the widths of five IDs.

3)a: Widen page container

The div #page is like a container for all of the rest of this layout. Add 200px to the width property.

Before editing:

 
#page {

   background-color: white;
   margin: 20px auto;
   padding: 0;
   width: 760px;
   border: 1px solid #959596;
   }

 

After editing:

 
#page {
   background-color: white;
   margin: 20px auto;
   padding: 0;
   width: 960px;
   border: 1px solid #959596;
   }

 

3)b: Increase width of header container

Add 200px to the width of both #headerimg and #header.

Original CSS:

 
#headerimg {
   margin: 7px 9px 0;
   height: 192px;
   width: 740px;
   }

 

After editing:

 
#headerimg {
   margin: 7px 9px 0;
   height: 192px;
   width: 940px;
   }

 

Original CSS:

 
#header {
   background-color: #73a0c5;
   margin: 0 0 0 1px;
   padding: 0;
   height: 200px;
   width: 758px;
   }

 

After editing:

 
#header {
   background-color: #73a0c5;
   margin: 0 0 0 1px;
   padding: 0;
   height: 200px;
   width: 958px;
   }

 

3)c: Widen footer

Add 200px to the #footer ID’s width. After this step, WP Default’s text should be lining up with your new, wider images.

Before editing:

 
#footer {
   padding: 0;
   margin: 0 auto;
   width: 760px;
   clear: both;
   }

 

After editing:

 
#footer {
   padding: 0;
   margin: 0 auto;
   width: 960px;
   clear: both;
   }

 

3)d: Widen sidebar or add a second sidebar

Here you have a choice. You have room for two sidebars with the width of the original, or one wide sidebar. This should get you started.

Before editing:

 
#sidebar {
   padding: 20px 0 10px 0;
   margin-left: 545px;
   width: 190px;
   }

 

To make one extra-wide sidebar, simply add 200px to the existing sidebar ID. You’ll need to apply some floats and widths to the contents, but that’s a topic for another tutorial.

After editing:

 
#sidebar {
   padding: 20px 0 10px 0;
   margin-left: 545px;
   width: 390px;
   }

 

For double sidebar ideas and directions, also see Add a Second Widgetized WordPress Sidebar.

To style two sidebars, you can try duplicating whatever is defined by the first sidebar’s ID, #sidebar, but with a second, separate ID.

After editing:

 
#sidebar {
   padding: 20px 0 10px 0;
   width: 200px;
   float: right;
   }

 
#sidebar2 {
   padding: 20px 0 10px 0;
   margin-right: 30px;
   width: 200px;
   float: right;
   }

 

Reducing Header Height – WordPress Default Theme

The WordPress Default Theme measures about 220 pixels from the top of the screen to the bottom of the header image, with a 760px wide by 200px high header image. Many popular sites have only between 100 and 150 pixels between the top of the screen and the bottom of the header area. Users who don’t know php and want to change the height of the header will sometimes delete references to functions that can customize the colors of Kubrick’s custom header.

I think that’s a shame, if it’s in response to not wanting to mess with the unknown, because complete understanding is not needed. If the desire is a new image, replace away. If it’s less height now, a new image later, here’s a way to start by experimenting with changing the height. I’m a firm believer in learning by experimentation and observation. If you are a non programmer with similar tendencies this may be a fun exercise for you.

These are copy and paste directions. Programming skills are not required – simply pay careful attention to details. You’ll need basic image editing skills, a text editor like notepad, and the ability to FTP your theme’s files.

At the end, you will have taken 80 pixels off of the distance between the top of the screen and the bottom of WordPress Default theme’s header image.

  1. Step One: Change the header image height
  2. Step Two: Edit php that customizes image color
    • 2)a: Subtract 70px from height variable
    • 2)b: Find code that defines header shape coordinates
  3. Step Three: Change style sheet to match new image size
    • 3)a: Reduce height of header container
    • 3)b: Reduce top and bottom outside margins
    • 3)c: Re-center the blog’s name

Step One: Change the header image height

Look in /wp-content/themes/default/images/ for the file named kubrickheader.jpg. Use an image editing program to reduce the height by 70px. The only trick here is to avoid changing the radius of the corners. Avoid tools that change the scale of an image. Stick to copy and paste and you’ll be fine.

The original image is 760px wide and 200px high. I chose to take 70px off of the height, so my finished image is 760px wide and 130px high.

Step Two: Edit php that customizes image color

This gets a little more complicated, but you really don’t need to know how to write the php that draws color customizations. Just find the parts to change, and change only those without adding or subtracting spaces or punctuation. You’ll be changing the code in two places.

Look in /wp-content/themes/default/images/ for the file named header-img.php and open it in a text editor. If you’re like I was the first time I opened it, you don’t know much php but do remember enough algebra to recognize graphing coordinates.

2)a: Subtract 70px from height variable

Find where the height of the image is defined, and subtract 70px. The original height is 182px, not 200px, because the outside border is left white. Change $h = 182 to $h = 112.

Original code:

 
// Get the background color, define the rectangle height

$white = imagecolorat( $im, 15, 15 );
$h = 182;

 

After editing:

 
// Get the background color, define the rectangle height
$white = imagecolorat( $im, 15, 15 );

$h = 112;
 

2)b: Find code that defines header shape coordinates

This is where remembering algebra made me curious about what would happen if I changed the coordinates. Since the height is reduced by 70px, the bottom corners will need to be moved up the y axis by 70px. Subtract 70 from the first number in the last five rows of numbers, and you’re through with this step.

Original code:

 
// Define the boundaries of the rounded edges ( y => array ( x1, x2 ) )

$corners = array(
	0 => array ( 25, 734 ),
	1 => array ( 23, 736 ),
	2 => array ( 22, 737 ),
	3 => array ( 21, 738 ),
	4 => array ( 21, 738 ),
	177 => array ( 21, 738 ),
	178 => array ( 21, 738 ),
	179 => array ( 22, 737 ),
	180 => array ( 23, 736 ),
	181 => array ( 25, 734 ),
	);

 

After editing:

 
// Define the boundaries of the rounded edges ( y => array ( x1, x2 ) )
$corners = array(
	0 => array ( 25, 734 ),
	1 => array ( 23, 736 ),
	2 => array ( 22, 737 ),
	3 => array ( 21, 738 ),
	4 => array ( 21, 738 ),
	107 => array ( 21, 738 ),
	108 => array ( 21, 738 ),
	109 => array ( 22, 737 ),
	110 => array ( 23, 736 ),
	111 => array ( 25, 734 ),
	);

 

Step Three: Change style sheet to match new image size

Look for style.css at /wp-content/themes/default/style.css, and open it in a text editor.

3)a: Reduce height of header container

Take 70px off of the height of the ids #headerimg and #header. In the WordPress Default theme #header appears twice, because of the way the Michael Heilemann has separated structure and formatting. It’s OK to either leave them separate or combine them. To keep it simple here for beginners I’ve left them separate, like they are in the original style sheet.

Original CSS:

 
#headerimg 	{

	margin: 7px 9px 0;
	height: 192px;
	width: 740px;
	}

 

After editing:

 
#headerimg 	{
	margin: 7px 9px 0;
	height: 122px;
	width: 740px;
	}

 

Original CSS:

 
#header {
	background-color: #73a0c5;
	margin: 0 0 0 1px;
	padding: 0;
	height: 200px;
	width: 758px;
	}

 
#headerimg {
	margin: 0;
	height: 200px;
	width: 100%;
	}

 

After editing:

 
#header {
	background-color: #73a0c5;
	margin: 0 0 0 1px;
	padding: 0;
	height: 130px;
	width: 758px;
	}

 
#headerimg {
	margin: 0;
	height: 130px;
	width: 100%;
	}

 

3)b: Reduce top and bottom outside margins

If you want, you can lessen the margin between the top edge of the screen and the top of the header image. If so, you’ll need to find #page.

Original CSS:

 
#page {
	background-color: white;
	margin: 20px auto;
	padding: 0;
	width: 760px;
	border: 1px solid #959596;
	}

 

After editing to reduce the top and bottom outside margins by 10px:

 
#page {
	background-color: white;
	margin: 10px auto;
	padding: 0;
	width: 760px;
	border: 1px solid #959596;
	}

 

3)c: Re-center the blog’s name

The original CSS allows for 70 pixels of padding above the site’s name. Now that 70px has been taken off of the header height, 35 pixels needs to be removed from top padding.

Before editing:

 
/*	Begin Headers */
h1 {
	padding-top: 70px;
	margin: 0;
	}

 

After editing:

 
/*	Begin Headers */
h1 {
	padding-top: 35px;
	margin: 0;
	}

 

Breaking the Mold Without Breaking Myself

Creativity is a bit like a butterfly net. A butterfly net can be a tool, an unused artifact, a source of silly visual jokes and metaphors – determining its significance requires perspective. Most of us don’t have a butterfly net on hand at any given moment, and a net doesn’t do much on its own.

Someone needs to pick it up and be ready to act, and then there are always more questions:

  • Where are the butterflies?
  • Am I going after the right butterflies?
  • Should butterflies be caught, mounted in a collection, bred in captivity… or in this case are they better admired in the wild?
  • How many is enough?
  • What is this other thing that landed in my net?
  • Is running around waving a net really the best use of my time?

Weekend Off? Wax On

This is post 23, published on day 31 of my goal of 101 posts in 101 days. I’ve been writing every day and posting almost every day. Along with publishing 23 new finished posts, I’ve saved about 12 new drafts and made about three more “draft” pages that are lists of ideas and links I like, and my “ideas” notebook is beginning to fill up.

At about post #10 I noticed that writing was getting easier, though writing something finished every day was harder. I decided to try posting twice in one day once in a while, still working on drafts when I wasn’t going to post that day. That may not be the best path for me: the need for a day off got stronger, and finishing things got harder.

Part of the problem was feeling like I’d let go of discipline by not posting every day, though sometimes, hey, the fruit is on the tree but not ripe for picking, if you know what I mean. I decided to experiment with purposefully taking time off from posting and writing, to see what would happen between my ears. Would I get better results from “I will take this weekend off,” or from “I will do all I can and take a day to myself if I need it?” Not posting for a day, no matter how purposeful, didn’t feel much different from slacking off because of burnout. Something was missing.

A couple of weeks ago I forced myself not to post over the weekend, and it was a surprising experience.

During that two days I had a sudden flood of creative ideas and even some practical ones. I felt like I’d experienced something wonderful about balancing pushing myself with leaving open space, and I was eager to get back to work. Then, that Monday, Tuesday and Wednesday were exhausting, like pulling my own teeth while under the influence of not enough anesthetic. I was more tired than before giving it a rest.

Observations:

  • Change of pace is good for creativity.
  • Getting self-discipline going after a break is hard.
  • Balancing the two is challenging!

Discipline Is Good For Learning and Building

Achieving something when creativity comes to call requires that skills and tools are in place ahead of time. Skills and the use of tools requires practice, practice and more practice – like exercise. Every exercise that requires effort builds something.

Working out is like making art

Drawing every day improves coordination. Hand-eye coordination, small muscle coordination, and the big stuff of muscle memory are all grown in the brain and the body, through practice and desire. Instinct may be inborn, but the ability to do something with it or even to notice opportunities is not automatic and doesn’t happen over night.

Art students are sometimes advised to put their heart into every drawing, but not to expect to be making precious objects. Draw every day for the experience of drawing, and expect the first hundred to be throw aways. After the first hundred, drawing is a little more likely to occasionally result in art. Experimenting with CSS can feel much the same way. ;-)

Regular practice is essential. Without daily practice the coordination starts to go, and then the would-be artist is left with hope and vision, or hope for a vision, or maybe just insecurity and desire: one of the side effects of practicing through clumsiness is a quiet bravery.

Bravery comes in handy. The creative process can be ruthless and klutzy, like a kid running around with a butterfly net.

The Plan

The goal is still 101 posts in 101 days. If I need to go to six posts a week to stay human, that’s OK, but the existing goal is still 101 posts in 101 days. At the end of the road will be a sense of identity (brand) for this space.

The plan is to post daily except for weekends. Though it’s Sunday evening here, you’re hearing from me today because I felt like it. Weekends are mine.

Insert evil laughter?

Who let that blogger out without a net?

Seriously, though, here’s a forecast for the week to come:

  • Three more tutorials
  • An interview with the delightful Dazzlin D – we’re going to talk about community. Yum.
  • Between two and four other I-don’t-know-whats, to include a drawing of some sort.

Is this hasta la vista, or how can I hasta la forest for the vista of the trees, from my viewpoint of this rectangular screen where we meet? Either way, trees are cool and I’m up for a good walk.

WordPress: Add a Second Widget-Ready Sidebar

This is the tutorial I wish I had found when I first wanted to know how to add a second widget-ready sidebar.

  1. Step One: Create a second sidebar file
    • 1)a: Add content to sidebar2.php
    • 1)b: Upload sidebar2.php
  2. Step Two: Add the new sidebar to your WordPress layout
    • 2)a: Find the code that calls the original sidebar
    • 2)b: Add your own includes
  3. Step Three: Use functions.php to tell your theme about the new sidebar
    • 3)a: Insert widget-ready CSS
    • 3)b: check your work

Step One: Create a second sidebar file

Create an empty text file and give it a name. For the purpose of these instructions I’m using the file name sidebar2.php.

1)a: Add content to sidebar2.php

The example below will work for a second widgetized sidebar. Surrounding the second sidebar with a CSS div named “sidebar2” provides a way to control positioning and use styling independent from another sidebar.

Note the difference between the original dynamic_sidebar() that you’ll you’ll find in a single sidebar theme, and the use of dynamic_sidebar(2) for a second sidebar. This difference is how the dialog at Options > Themes > Widgets knows which sidebar gets which widgets.

 
<!-- begin sidebar2 -->
<div id="sidebar2">
<ul>
     <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(2) ) : else : ?>

     <?php endif; ?>
  </ul>
</div>
 
<!-- end sidebar2 -->

 

1)b: Upload Sidebar2.php

The new sidebar should go in the directory containing your theme. If you’re using the WordPress Default theme, you need to upload it to /wp-content/themes/default/.

Step Two: Add the new sidebar to your WordPress layout

Decide where you want the contents of your second sidebar file to appear on a page, and in what kinds of pages. Some possible destinations are index.php, single.php, page.php, 404.php, search.php, and archives.php. What you choose will depend on your needs.

2)a: Find the code that calls the original sidebar

Where does the original sidebar appear now? The home page? The single post view? Some template files will contain a way to insert the existing sidebar. Methods that may be used will look something like one of these three examples.

This first example uses the WordPress include tag, get_sidebar. In this case, if a theme doesn’t have its own sidebar.php, WordPress will use the sidebar.php from the WordPress Default theme.

 
<?php get_sidebar(); ?>
 

These next two examples use a php “include” to call a single sidebar with the file name sidebar.php. The first assumes that sidebar.php is in the same directory as any template files containing this code. The second specifies TEMPLATEPATH. TEMPLATEPATH is the default location for the files contained in whatever theme is currently in use. Either will work, unless you’re doing something fancy that is out of the span of this tutorial.

 
<?php include("sidebar.php"); ?>

 

 
<?php include(TEMPLATEPATH."/sidebar.php");?>
 

2)b: Add your own includes

Use a separate include for each sidebar. In both examples below, the first include will call the original sidebar, if it has the default file name of sidebar.php. The second will call our new sidebar, with the file name of sidebar2.php. Place the sidebar.php line where you would like to see sidebar.php’s contents generated, and the sidebar2.php line where you want sidebar2.php to appear.

 
<?php include("sidebar.php"); ?>
 
<?php include("sidebar2.php"); ?>

 

Or you could use this:

 
<?php include(TEMPLATEPATH."/sidebar.php");?>
 
<?php include(TEMPLATEPATH."/sidebar2.php");?>

 

Step Three: Use functions.php to tell your theme about the new sidebar

Think of functions.php as a sort of a master of ceremonies for instructions specific to your WordPress theme. The simplest, widgetized, single-sidebar theme will have a functions.php file that contains something like this, without further specifications:

 
if ( function_exists('register_sidebar') )

  register_sidebar();
 

To add a second sidebar to such a simple theme, change the “1” to a “2” and make “sidebar” plural. If you’re adding two sidebars, change the “1” to a “3.”

 
if ( function_exists('register_sidebars') )

  register_sidebars(2);
 

3)a: Insert widget-ready CSS

A few more lines of code make a big difference, giving more control over CSS and automatically creating a lovely, nested navigation list. For an example, take a look at the first few lines of the functions.php that comes with WordPress’s single-sidebar Default theme. That theme and some others have special CSS powers because of a slightly more complicated funtions.php. In the example below, where you see li id="%1$s" and class="widget %2$s", WordPress will automagically insert IDs and classes named after whatever widget is displayed. To make use of those IDs and classes you’ll need to edit your stylesheet.

 
if ( function_exists('register_sidebar') )
  register_sidebar(array(

    'before_widget' => '
<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>
 

',
    'before_title' => '
<h2 class="widgettitle">',
    'after_title' => '</h2>

 
',
  ));
 

To add a second widgetized sidebar and retain the nifty formatting by the example above, you could add a curly bracket to the end of the first line, make “sidebar” plural and add the number 2 on the second line, and nest the whole thing with a closing curly bracket on the eighth line. The result will look like this:

 
if ( function_exists('register_sidebar') ){

  register_sidebars(2,array(
    'before_widget' => '
<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>

 
',
    'before_title' => '
<h2 class="widgettitle">',
    'after_title' => '</h2>

 
',
  ));
}
 

Two sidebars should now show up at Presentation > Widgets.

3)b: Check your work

Open your home page and click refresh. At this point, your site might look odd because of CSS layout problems, but there should not be any php error messages. If something besides CSS styling is off, re-trace your steps and check for typos, missing bits or extra spaces before and after php opening and closing tags.