All Killer WordPress Websites are Built Around These Concepts
This guest post was written by Matt Dunlap who blogs about website development. If you have webmaster or WordPress knowledge and are interested in writing a post for WordPress Hacks, please contact us.
I’ve been coding with WordPress for a long time now. All the way back to when there was a my-hacks.php file. Shortly thereafter WordPress introduced plugins and widgets. Over all these years I find myself going back to a few key WordPress concepts that make blogs really functional.
- Popularity of Posts – The plugin I use, and hack often, is Alex King’s popularity plugin. If you download it from wordpress.org, it works great, but if you really want to make some cool features, you are going to have to hack it.The popularity plugin displays the most popular posts based on time frame, or category in a list (<li>)by default. I’ve hacked it to get the the raw posts, so I can do my own formatting. You can see an example in my “hot list”.
- Related Content – Notice how I didn’t say related posts. Finding related content goes much deeper then posts or pages.Related content is a must to build loyal readers (repeat visitors). You have to guide your readers and help them find content THEY are interested in. Remember, most people will find your content from Google, so feed them some related content and grow your user base. Related posts are easy to get, you simple have to a fulltext index to your database. You can then match terms to keywords.
- Categories – WordPress is nothing more then a way to organize your content, hence the term CMS (Content Management System). 80% of my traffic from Google comes from a relation to WordPress categories. Either trying to display top level categories without children, or trying to build a top menu/submenu navigation menu.Working with categories in WordPress can be pretty frustrating. I wish there was better information. Luckily there are a lot of help from the WordPress Community.
- Images – Magazine themes are the most popular style of theme on the Internet. It’s all about the cool graphics and images to get reader to click on posts. Content sliders and featured content sections with large graphics can be a pain to manually update, which is why you need to learn how to manipulate the images from your posts.
There you have it. If you want to be a WordPress hacker and make killer websites, you gotta have a good working knowledge of those four topics. Thanks for reading my post, and as always, don’t be scared to ask me for help.
How To: Add a Twitter Link to Your WordPress Blog
Twitter is all the rage these days and it doesn’t seem like it will be going anywhere any time soon. With that said, it often surprises me that many WordPress blog owners don’t offer a convenient way for their readers to retweet their content. Anyone can grab a Twitter WordPress plugin to tweet their new content as it is published, but what about your older content?
Rather than passing up all that potential traffic, I’ve found that offering a link somewhere within your post (optimally at the bottom of each post) is a great way to help your readers and incoming search engine traffic to promote your content for you. When people find great content they like to share it with others, so why not make it easy for them?
Not only is adding a “Tweet This!” link a great choice, but it is really easy to do. Chances are if you do a search on Google for code to use you’ll find something like the following:
<a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>" title="Click to send this page to Twitter!" target="_blank">Tweet This!</a>
This code works just fine, but is not the most optimal solution in my opinion. Depending on the permalink structure your WordPress blog uses, combined with the length of your domain name, it may be difficult to fit the link into a 140 character tweet. It also doesn’t leave room for the person to add their own comments to the tweet.
As a proposed solution, I recommend using some WordPress code like the following:
<a href="http://twitter.com/home?status=RT @HackWordPress <?php the_title ();?> <?php echo get_settings('home'); ?>/?p=<?php the_ID(); ?>">Tweet This</a>
This code will automatically insert the “RT” and your Twitter account name (the above example uses our Twitter account, @HackWordPress) then use the ID form of your post with the tweet. When people click the link in the tweet, they will then be redirected to the actual post using your blog’s selected permalink structure, making a convenient and typically short URL.
Have you integrated Twitter into your WordPress blog? Share your strategies in the comments!
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!
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.
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?













