How to Display Categories in Drop-Down Box

Personally, I prefer to display my blog categories without in drop down box, but if you really have many categories on your blog, perhaps you can display categories in drop-down box so that your blog will looks more neat.

Below is the simple code to display categories:-

<h2>Categories</h2>
<ul>
<?php wp_list_cats('sort_column=name'); ?>
</ul>

To display categories in drop-down box, use the following code.

<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?>
<noscript><input type="submit" value="View" /></noscript>
</form>

How to Exclude Certain Categories

There are 2 ways to exclude certain categories from your blog, one is use wordpress plugin named Advanced Category Excluder. This plugin was born because there was a no other real alternative to enable content sparationd and some CMS like functionalities in WordPress. The main goal was, to enhance WordPress’s functionalities, to hide some unwanted categories, from defined parts of the blog.

The alternative way is without plugin, you can add the below code inside the loop then it will work.

<?php
if ( have_posts() ) : query_posts($query_string .'&cat=-1,-2'); while ( have_posts() ) : the_post();
?>

How to Highlight Author’s Comments

There are 2 ways to highlight author’s comments, one is use highlight author comments wordpress plugin, another idea is without wordpress plugin. If you don’t want to use wordpress plugin to highlight author’s comment, you can follow the below few simple steps.

First, you need to open styles.css and add the following into this file.

.authorstyle { background-color: #B3FFCC !important; }

Second, open comments.php, find and locate the following code.

<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>"></li>

And then replace with

<li class="<?php if ($comment->user_id == 1) $oddcomment = "authorstyle"; echo $oddcomment; ?>"></li>

Please note that you must change 1 to the user id of the author. Thanks to Matt Cutts for this tutorial.

How to Display Recent Posts from Specific Category

Initially I was thinking to display all the posts from specific category in my archives page, but this doesn’t work well if you have thousand of posts for one category, that’s why I want to limit the number of recent posts displayed from specify category.

To display recent posts from specific category, you can make use of the following coding. To change the number of displayed recent posts, simply change the showposts=10 to your desired number; cat=1 is your category number, you have to change this too.

<ul>
<?php $recent = new WP_Query("cat=1&amp;showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a></li>
<?php endwhile; ?>
</ul

In case you need to display all posts from specific category, then you can use the following coding. cat=6 is your category number, please change it.

<ul>
<?php query_posts('cat=6'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php $wp_query->is_home = false; ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> – <?php the_time('j F Y') ?></li>
<?php endwhile; endif; ?>
</ul>

Thanks to Ready WP Themes for this coding.

How to Add Avatar to Your Comments

The default wordpress themes are came with avatar support. In case you have use some other free or premium wordpress themes with no avatar support, then you can adding the following simple and short coding to your comment.

<?php echo get_avatar( get_the_author_email(), '80'); ?>

get_the_author_email outputs the post author’s email and the “80” is the size of the avatar image in pixels, you can change the size of the avatar according to your needs. Is it looks simple? @@

How to Display Post Words Count

I don’t know why some people like to display post words count on their blog, but I personally don’t like this function. In case you are the ones like this function, then you can copy and paste the following coding to functions.php.

function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(" ", $content));
}

And then you can call the function to get the number of words of the current post:

<?php echo wcount(); ?>

Thanks to Digging Into WordPress for this excellent code.