WordPress Category Page Hacks

by @jehiah on 2004-10-06 12:19UTC
Filed under: All

The following two hacks will increase the usability of WordPress category pages by giving an index of posts instead of a paged overview, and by sorting posts by title instead of post date.

Index

To change your category pages to an index of titles instead of including excerpts from posts, add the following to your index.php page around the normal if ($posts) : foreach ($posts as $post) loop.

[php]
<?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(); ?>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a><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
}
?>
[/php]

Sort

Insert the following code in wp-blog-header.php at line 345 to order the category pages by title instead of date. This is a simple way to increase usability as users who are looking for content have no clue when information was posted.

[php]
if ($whichcat)
{
    $orderby = 'title';
    $order = 'ASC';
}
[/php]
Subscribe via RSS ı Email
Jehiah Czebotar