By default, a typical WordPress blog will display the very first comment at the top of the comments template. While I prefer this way, many others do not. If you are someone that would like your WordPress blog to display the most recent comment on top, Moses of WPThemesPlugin.com explains how to display recent comments on top.
Unlike most of the WordPress hacks we’ve covered here at Hack WordPress, this one is not something that can be controlled from within the WordPress theme. You’ll have to actually go into the comment-template.php file (in the wp-includes folder) in order to make this adjustment. The good news is that it is REALLY easy. Click over to get step-by-step instructions on how to complete this hack. Great work Moses!
When you think of having two stylesheets for a website or blog, you typically think of an alternate stylesheet specifically for a web browser, such as an Internet Explorer stylesheet.
One thing we haven’t covered yet is how to add a second stylesheet that is only used for certain pages. In order to do this, you’ll want to open up your header.php file and locate your existing stylesheet. The stylesheet code should look something like this:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
Now, we need to make an adjustment so that it will only show the code in a certain situation. For example, if you want a certain category to use a different stylesheet, you’d use the following code:
<?php if ( is_category('1') ) {
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/cat-1.css"
type="text/css" media="screen" />;
<?php } else { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"
type="text/css" media="screen" />
<?php } ?>
In this example, we are assigning the cat-1.css to be used for category 1. Every other page will use the normal stylesheet.
You can plugin in alternate information as needed.
As we continue to gear up for WordPress 2.5, have you gotten your theme ready for Gravatars? In the past it required plugins, but now WordPress 2.5 has built-in Gravatar support. This means going forward, themes can easily be released with Gravatars built-in to the theme because no plugin will be required.
So, you’ve got WordPress 2.5 installed and you’re ready to assign Gravatars to your comments? All you need to do is a quick code hack to the comments loop where you want the Gravatar to show up:
<?php if(function_exists(’get_avatar’)){ echo get_avatar($comment, ‘50’);} ?>
I encourage everyone to support WordPress by displaying Gravatars on their blogs once you’ve upgraded to WordPress 2.5.
Many WordPress themes are setup to display their category pages in the same format as your blog’s homepage, making your categories useless to some. This can cause duplicate content problems, as well as making your categories difficult to avoid. If this isn’t the case for you, then your theme is probably instead setup to just display a post excerpt for each post on your category page. I’ve never been a fan of this either, as this format strips your post of links/styles and doesn’t give you control over how much of the post to display.
Instead, I’ve always liked the idea of showing only the post titles on your category pages. If you are good at making post titles, this should help someone navigating your categories to find what they are looking for.
First, you’ll want to open your archive.php file and find the post loop. It usually starts with this code (or something similar):
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
You’ll want to delete everything from that code down to the end of the loop, which usually ends with this:
<?php endif; ?>
Now, you’ll want to replace the post loop code with the following slightly different code loop:
<?php $temp_category = single_cat_title('',false); if (!empty($temp_category)){ // give index ?>
<h1><?php single_cat_title(); ?></h1>
<p><?php echo(category_description(the_category_ID(false))); ?></p>
<?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li><br>
<?php endforeach; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php }else{ // give details or single post ?>
...... code for normal post overview
<?php } ?>
And you’re done! You can add<li>, <ol>, and whatever else as needed, and then style your archives page in your stylesheet to get the look you’re trying to achieve.
Over the past six months, Hack WordPress has covered a number of great WordPress hacks. If you’re a new subscriber and missed most of them, however, it would probably take you awhile to dig through all of these.
The author of Noupe.com has written a quality post about Mastering Your WordPress theme that features a large number of our hacks, as well as some other hacks that were scattered all over the blogosphere. If you’re looking for a good collection of WordPress hacks, I recommend you check it out!
As an added bonus, if you look closely you’ll see our Recent Comments section featured in the post.
WordPress.com is a wonderful and free way for people to begin blogging, but it is only natural for a blogger to eventually “outgrow” it and make the move to a self-hosted WordPress blog. Eventually the draw of being able to monetize your blog, combined with the lure of WordPress themes and WordPress plugins can be to much!
For those making the switch, it can be a period of adjustment as the blogger transitions from having everything done for them to having to do everything themselves. Michael Martine has written a great post walking people through making the move from WordPress.com to WordPress.org. If you are still on WordPress.com, I recommend you click over to check it out!








