• Resolved Jacorre

    (@jacorre)


    When clicking on a category that has no posts, it will direct you to the 404 page. Why is that? Shouldn’t it display what’s after the else section on the archive page?

    Here is my code:

    <?php get_header(); ?>
    
    <div id="content">
      <div id="content-left">
    <?php is_tag(); ?>
    		<?php if (have_posts()) : ?>
    
     	  <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
     	  <?php /* If this is a category archive */ if (is_category()) { ?>
    		<h2><?php single_cat_title(); ?></h2><div class="category-description"><?php echo category_description(); ?></div>
     	  <?php } ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    Post stuff goes here...
    
    		<?php endwhile; ?>
    
    <div id="page-nav">
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
    </div>
    
    	<?php else : ?>
    
    	<h2>Not Found</h2>
    	<?php include (TEMPLATEPATH . '/searchform.php'); ?>
    
    	<?php endif; ?>
    
    </div> <!-- END CONTENT LEFT //-->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    Based on the above, if there are no posts, shouldn’t it display:

    <h2>Not Found</h2>
    	<?php include (TEMPLATEPATH . '/searchform.php'); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • This is basically an error handling issue (not enough conditional statements). Also, take a look at the Template Hierarchy.

    Here’s some Trac tickets related to the issue: 3345 and 1969. The dev team is aware of the issue and a fix is in the works.

    Was this just an ‘academic’ question or do you need some sort of work around? (An easy fix would be to create a “placeholder” post with all categories selected.)

    Thread Starter Jacorre

    (@jacorre)

    Thanks for the reply, so it’s actually a bug then. I guess I can wait for the fix. I haven’t gone live with the site yet.

    I don’t have a generic category.php page but I do have an archive.php page. If I added a generic category.php page would that help or would it still not work because of the bug?

    Thanks!

    I was hoping for a fix too, but I see this thread started 3 months ago, so I suppose I need to assume that it’s not on the bug fix list any more.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘No posts going to 404 page?’ is closed to new replies.