WordPress 3.0 – Creating a Network (multisite)

WordPress 3.0 now has multisite functionality built in. It’s extremely easy to get a basic version of what used to be called wordpress MU installed. WP Theming has a video demonstrating how to get started; or, if you prefer, the codex has text instructions. Couldn’t believe how easy it was

1. Enable Multisite
2. Configure Multisite
3. Add a site

WordPress Function _n

I was wondering today what the wordpress function _n does. It is pretty straight forward. It returns the plural or single form of a string based on the number. Simple simple.

How to Add a Sidebar to a WordPress Theme

I recently needed a little more control over the sidebar on a theme and had never added a sidebar to a theme before. I wanted certain widgets to show up only on posts and the rest to show up on posts and pages.  The below is how to add the sidebar:

In the functions.php page, we need to modify the code which looks like this:

if ( function_exists('register_sidebar') )
	register_sidebar();

To make it look like this:

if ( function_exists('register_sidebar') )
{
	register_sidebar(array('name'=>'Top Sidebar',));
	register_sidebar(array('name'=>'Posts Sidebar',));
	register_sidebar(array('name'=>'Bottom Sidebar',));
}

Now, when calling a sidebar, we just need to call it by name as in the following:

//Top Sidebar
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Top Sidebar') ):
endif;
//Posts Sidebar
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Posts Sidebar') ):
endif;
//Bottom Sidebar
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Bottom Sidebar') ):
endif;

Obviously we have freedom to name our sidebars as we please.  Look for more info on making a sidebar only show up on posts in an upcoming post.

Getting $_POST variables in a WordPress Plugin on save

I’ve been making more and more wordpress plugins lately and it seems to me that a vital part is getting certain variables back once a post is saved. I had a bit of trouble on this since the logical hook of save_post() was not returning my variables. After a lot of messing around I came to the conclusion that if you use the init() hook you can pull your variables and do whatever actions there, however keep in mind, on init() wordpress is not loaded so you can’t use wordpress functions.

Anyway here is an example…

function checkCheckBox()
{
    global $_POST;
    if($_POST['checkbox'] == 1)
    {
       return true; // You would more likely set an option or define a constant here instead so it can be more global
    }
    return false;
}

add_action('init', 'checkCheckBox');

Hope this helps someone, I know it would have saved me alot of time if I knew.

Upgrading WordPress MU from 2.6 to 2.7

I know I’m late to the game but I tried upgrading wordpress from version 2.6 to 2.7 today.  I ran into the seemingly all-too-common redirect loop which seems to have to do with the wp-config.php keys and salts.

Thanks to a comment on the wordpress forums, I was able to find a resolution, which was to remove the block of KEYS and SALTS entirely from the wp-config.php file.  Then, upon login, MU notifies you that your keys are incorrect and asks you to update them.  A simple fix to something that I thought would be a major problem.

I have to say, WordPress 2.7 is significantly better than 2.6 AND 2.7 MU is even better than that if you are running multiple blogs.  What fun!