SDAC Blog

Check out our blog for WordPress updates, WordPress plugin reviews, and general web development hints.

hr
hr

There are some times when you want to limit your search to a particular category, or perhaps multiple categories. This is relatively simple to do in WordPress by adding a hidden field to your search code. (See example below)

PHP:
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div><input type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
<input type="hidden" name="cat" value="22" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>

You can see I added my hidden input field on the third line. When I add this in, it then adds onto the query used to search. Your search will go from something like http://www.sandboxdev.com/?s=WordPress to http://www.sandboxdev.com/?s=WordPress&cat=22 and will only return posts in the category ID you choose.

separate
hr
hr

I have been using WordPress for almost 4 years and have collected a number of database tables, plugin specific directories, and miscellaneous junk along the way on a number of my sites. I wanted to take some time and really do some spring cleaning. After a few hours - I was very pleased with the results and I wanted to share what worked for me.

Here are the steps I recommend to really clean out a WordPress installation:

  1. Make a backup of everything. You never know what you are going to get into - and a backup is very important incase things go bad.
  2. Make a test installation. I always use a test server when I know I am going to make several changes. This way, jappler.com was not down while I was testing and cleaning up. With your backup files, import your database on the test server, and grab the latest version of WordPress (hopefully using subversion)
  3. Remove old or unused plugin database tables. I then went into the WordPress database and removed (dropped) any tables that were created by any of my old or unused plugins that were still hanging around.
  4. Weed out old, unused plugins. I went through my plugins and deleted any old or unused plugins. I had a few "I should really use this" plugins that were never used - and to tidy up - I deleted them before uploading them to the test server environment. Make sure to also remove any files/folders that old plugins might have used in the root folder and or wp-content.
  5. Move your theme over. Upload the theme file over to the test server.
  6. Move your uploads over/miscellaneous files. Upload the uploads folder (wp-content) so you will have all your old uploads.
  7. Update WordPress. Run through the upgrade process (/wp-admin/upgrade.php).
  8. Debug your plugins. Log in, create a test post to make sure you can write to the database without any errors. I ran into a few problems with this, so I deactivated my plugins and activated them one by one. I found I had a few plugins that were not compatible with WordPress 2.3, but there were updates available, so I updated my plugins and moved on.
  9. Import Tags (if you have them). I used Ultimate Tag Warrior and WordPress has an import option for that (Manage > Import) for that.
  10. Display your WordPress tags in your WordPress theme. Now that tagging is available within WordPress without any plugins, you can easily display tags by using:
    PHP:
    <?php the_tags(‘before’, ’separator’, ‘after’); ?>

    You can also use a tag cloud (see Codex documentation)

  11. Make another backup. I always make another backup of my sites when I am happy with the end result - just incase something happened - I would not lose all my hard work.
  12. Enjoy your updated installation. Hey - you did it! A clean, lean, updated web site. Nice work. Now go and enjoy it!
separate
hr
hr

Ever wonder how some web sites have little icons (gravatars) next to peoples' comments? If you would like to have this functionality on your WordPress blog or web site, check out the WordPress documentation on gravatars.

separate
hr
hr

If you have a project where you are using

HTML:
<object> and <embed>

and in IE, when you hover over the flash object and a border appears, there is a fix available: SWFObject: Javascript Flash Player detection and embed script. I have used it with some flash sites and it works great.

separate
hr
hr

Ever wonder how to automatically highlight your tabs or navigation depending on the category, page, or post you are on? Wonder no more! To make this work, there are three bits of code you will need:

  • The header code to control the body ID (and to tell us what page we are on)
  • The navigation code
  • The CSS to control the highlight

For this example, I will use this web site as an example.

The header code

PHP:
<?php
$current_page = $post->ID;
$parent = 1;
while($parent) {
$page_query = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
$parent = $current_page = $page_query->post_parent;
if(!$parent)
$parent_name = $page_query->post_name;
}
?>

<body id="<?php echo (is_page()) ? "$parent_name" : ((is_home()) ? "blog" : ((is_search()) ? "other" : ((is_single()) ? "blog" : "blog"))); ?>">

The XHTML code (navigation)

HTML:
<div id="tabs">
<ul>
<li id="nav-home"><a href="/index.php">Home</a></li>
<li id="nav-blog"><a href="/blog/">SDAC Blog</a></li>
<li id="nav-websolutions"><a href="/web_solutions/">Web Solutions</a></li>
<li id="nav-networksolutions"><a href="/network_solutions/">Network Solutions</a></li><li id="nav-userinterfacesolutions"><a href="/user_interface_solutions/">User Interface Solutions</a></li>
<li id="nav-customsolutions"><a href="/custom_solutions/">Custom Solutions</a></li>
<li id="nav-search"><a href="/search/">Search</a></li>
</ul>
</div>

The CSS code

CSS:
#home #nav-home, #about_us #nav-home, #contactus #nav-home, #faqs #nav-home,
#disclaimer #nav-home, #search #nav-search,
#blog #nav-blog, #web_solutions #nav-websolutions, #network_solutions #nav-networksolutions,
#user_interface_solutions #nav-userinterfacesolutions,
#custom_solutions #nav-customsolutions, #tos #nav-home, #sitemap #nav-home {
      background:url("images/tabs/active_tab_bg.gif") repeat-x;
      border-right:1px solid #676e78;
      }
         
#tabs li:hover, #tabs li:hover a {
    background: url("images/tabs/active_tab_bg.gif") repeat-x;
    color:#212933;
    }

General information
When you view the code for a page, you will notice that the header code will find out if the page viewed is infact a page. If it is a page, it gets the page parent (I use parent and child pages in my web site organization). The tabs are created with unique li IDs. So that a combination of #home (the body ID) and the #nav-home (li ID) will show as a highlighted tab. With this example, this case will only occur when we are on the home page because #home is a page (the home page) so the home tab will be highlighted. When we click on "SDAC Blog", the body ID will then be #blog, so now the #blog #nav-blog combination will force the "SDAC Blog" tab to be highlighted. Take a look at the CSS to see where to define the "cases".

Hopefully this took some of the mystery out of working with WordPress, navigation, and how to put everything together.

separate