Tutorial :WordPress: don't show 404 when no posts exist



Question:

Currently there is a bug in WordPress if you have a Posts Page set under:

Settings->Reading->A Static Page->Posts Page

If there are posts, than the page (e.g. with a slug called news) displays the post, and uses index.php from the theme.

But, with this configuration, if there are no posts, then it calls the theme's 404 page. This is definitely a bug, and has been submitted (Ticket #10822). It should be letting index.php show whatever it wants upon !have_posts(), but right now the page doesn't seem to be called at all.

My question is: is there a workaround for this bug without modifying core wp files? I'd be open to a plugin, theme changes, a custom page template, htaccess changes, etc.


Solution:1

I just performed a test for it. It isn't actually serving a 404, it's using index.php but since no posts are found so it falls outside of the have_posts(). Are you sure it's not a plugin or theme causing your issue? I tested this with the default theme on a base install of WordPress.


Solution:2

Most theme files have as part of their WP loop a catch for no posts, i.e.:

<?php else : ?>  Sorry, but you are looking for something that isn't here.  <?php endif; ?>  

That might be what you're seeing. You can use a custom page template without that text (leave the loop) for yoiur posts page. And try Reveal Template | coffee2code.com to find out what template file you're looking at.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »