WordPress: Remove Date From Posts on Category Page

Posted: October 4th, 2011 | Author: | Filed under: wordpress | No Comments »

The first thing you will need in order to remove the date from category pages is the id of the category which you wish to hide the dates on. To get the id click on ‘Categories’ in the admin and then click on the actual category you wish to affect. In the url you will see the id, similar to this:

In this instance, our ID is ’42′. Next you will need to find the file that you need to add the code into. By default WordPress will look in

\wp-content\themes\'your-theme'\

for the file in this order:

  1. category-slug.php (Note: available with Version 2.9)
  2. category-ID.php
  3. category.php
  4. archive.php
  5. index.php

Once you have found the appropriate file modify it like so around line 53 near the h2 tag:

<?php //hide date for category
	$show_date=true;
	$cat_array =  get_the_category($post->ID); 
	//print_r($cat_array);	
	$count = count($cat_array);
        for($i=0 ; $i < $count; $i++){
            $cat_id = $cat_array[$i]->cat_ID;
	    if ($cat_id == 42){
	        $show_date = false;
	    }
        }
if ($show_date) {?>
<span class="date"><?php the_time('d M'); ?></span>
<?php
}
?>

Be sure to replace the number on this line

 if ($cat_id == 42)

with this ID from above.
If you wish to hide the date on individual posts, you can add the same code to ‘single.php’

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • RSS
  • StumbleUpon

Related posts:

  1. Create Blank Page for WordPress Blog Using Your Theme Template
  2. Block Spammers by IP address in WordPress


Leave a Reply