Page Sensitive Multi-Level Navigation

While most sites don’t need incredibly deep page navigation there are situations that justify a hierarchy beyond the typical 2 – 3 levels.  Unfortunately that can be cumbersome for top navigation drop-downs (more than 1 level of drop down is too much IMHO) so another solution needs to be found.  I ran into just such a situation for a client and while I”m also not a fan of left hand navigation it was the decision of the client to utilize it in conjunction with their top navigation, and in retrospect it made sense for them. To keep things easily navigable we also implemented breadcrumbs (which is a good practice anyway).

The mission was to display sub-pages of the current page you are on in the left nav and once you hit the bottom of the hierarchy to show pages which are parallel to that page within the same branch of the hierarchy.

After some digging and experimentation I came up with the following which executes perfectly in only a few lines of code.

<?php
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
if ($children == "")
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1");
?>
<ul>
<?php echo $children; ?>
</ul>
<?php endif; ?>

Of course you style to taste…

That’s it! Used in conjunction with a standard WordPress top-navigation and breadcrumbs you can easily display page sensitive multi-level navigation for your super-complex multi-level site!

Tweet This | Digg This | Stumble it |

Security Reminder: Upgrading Your WordPress Blogs

While I was away over the weekend, it appears that a large number of bloggers who use WordPress have been hacked and a lot of damage has been done.  It seems this problem has shown up for a large number of people, including some very high profile bloggers.  Among them was Robert Scoble, whose blog was among those websites which were hacked.   Damages on Scoble’s site included porn information being placed in old posts, 2 entire months of content being deleted, and more.  Of course the porn then led to his blog being completely banned from Google!   Scoble is not the only one having these problems, however, and even lesser known bloggers have been attacked.  You can read more in this WordPress support forum thread.

If you are wondering what the one thing all of these WordPress sites have in common, the problem is they were all using old versions of WordPress.   As someone that owns and operates well over 100 WordPress installations, I certainly understand the pain it can be to upgrade to the latest version of WordPress every time a new release happens, but I hope this goes to show why it is so important to take the time to upgrade all of your WordPress installations be using the most recent version of WordPress.

Tweet This | Digg This | Stumble it |

Separating Trackbacks from Comments in WordPress 2.7+

Back when WordPress 2.7 was released, the WordPress team introduced a completely revamped comment form that included integration of threaded comments into the core software, introducing some dramatic changes with how comments are handled.   Unfortunately, this change broke one of the most popular comment hacks, separating trackbacks from comments.

Since then, several people have stepped up and shared some great hacks for separating trackbacks from comment in WordPress 2.7 or newer blogs .  So far the best guide I’ve found came from Sivel.net, which can be viewed here.  Click over and follow those steps get everything separated.

Note: The above guide is only for people using WordPress 2.7 or newer installations.  For people using WordPress 2.6 or earlier, you’ll want to use this tutorial.

Once you’ve got the comments successfully separated from the trackbacks, there are a couple additional tweaks you may want to do to clean up how things look (it really depends on preference I suppose).   The first is to clean up your trackbacks/pingbacks by only displaying the title instead of an excerpt and everything else.   In order to do this, you’ll need to find the following code in your comments.php file:

<ol>
<?php wp_list_comments('type=pings'); ?>

Now replace that code with the following:

<ol>
<?php wp_list_comments('type=pings&callback=list_pings'); ?>

Lastly, you’ll need to add the following code to your functions.php file (which can be created if you don’t already have one):

<?php
function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
<?php } ?>

That should clean up the trackbacks/pingbacks section and you can also apply the same changes if you use a plugin to display tweetbacks.

The other thing you may want to do is fix the comment count to only show actual comments, filtering out the trackbacks/pingbacks which are included in your comment count by default.   Simply add the following code to your functions.php file (which again can be created if you don’t already have one):

<?php
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
if ( ! is_admin() ) {
global $id;
$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
return count($comments_by_type['comment']);
} else {
return $count;
}
}
?>

So there you go.  Anyone have any other tips for cleaning up your comment form?

Tweet This | Digg This | Stumble it |

Few Improvements to the WPHacks.com Design

This post is just a heads up to let everyone know that the WordPress Hacks theme has been updated with a few new features added, courtesy of my friends at Blog Design Studio.  Some you will notice right away, while others you may not. 

Here are the notable changes included with this new update:

  1. Threaded Comments – Now that the discussions have increased in the comments of our posts, I felt that it was important to support threaded comments, which became available way back when WordPress 2.7 was released.    You can now reply to individual comments without them falling all the way to the bottom of the page.
  2. Twitter Integration – Twitter is quickly replacing FeedDemon as my “feed reader” of choice, and I know I’m not the only one.  As a result, I felt it was important to integrate Twitter into the WPHacks.com design.  You’ll now find recent tweets in the sidebar, a tweet this button below each of our posts, and the comments section now supports the Tweetbacks plugin, displaying your tweets about WordPress Hacks content.
  3. Author Profiles – Single pages now display author profile information below each post.  If you have written for us in the past and have your own author page, you may want to contact me to request I update the information, or you can login to your author account and update your profile page!  

The remaining changes were mostly “under the hood” things done to clean up the code a little bit and make sure everything was running smoothly.  If you have any questions or notice anything that isn’t appearing correctly, please let me know!

Tweet This | Digg This | Stumble it |

WordPress News & Notes – July 24, 2009

These days there are so many excellent WordPress blogs and articles, it can be hard to keep up with all the brilliant WordPress articles around, so here are some great articles I’ve saved on my feed reader; feel free to add some posts you’ve found around the web in the comments.

  1. First up, ‘10 Handy WordPress Comments Hacks‘ on Smashing Magazine by Jean-Baptiste Jung of WP Recipes fame.
  2. Next, a post on Chris Coyier and Jeff Starr’s Digging into WordPress caught my eye: ‘Include jQuery in WordPress (the right way)‘. In this post, as you might have guessed, Chris shows how to include jQuery the right way – using the copy of jQuery built into WordPress.
  3. Third, a post on WPWebHost in two parts – ‘Securing your WordPress Install the Foolproof Way’ – parts one and two. A couple of tips in there that you might not have thought of.
  4. Another post that caught my eye was ‘Multiple WordPress Loops Explained‘. I would say more, but it’s pretty self explanatory.
  5. A post that has been around a while, but is worth mentioning anyway – WPCandy presents ‘10 Things You Can Do With WordPress Besides Blogging‘. Again, pretty self explanatory, but definately worth a look.
  6. And finally, a little plug for a post I wrote the other day – ‘10 Tips to Improve Your WordPress Theme‘. Check it out. Some rather nice tips in there.

And there we have it. Six links of note!  Add your own in the comments.

Tweet This | Digg This | Stumble it |