• I’m using custom url in my theme and have made my own template hiracical (i can’t spell it!).
    So, in some situations I want to tell the wp that a 404 error happens, so use the 404.php to make the page. how to do that?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’d like to know this one too!

    Hi,

    Set your desired permalink and add this code in htaccess:

    `# BEGIN WordPress

    <IfModule mod_rewrite.c>
    ErrorDocument 404 /index.php?error=404
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress`

    Thanks,

    Shane G.

    Robert Chapin

    (@miqrogroove)

    Hi Shane, it seems you’ve missed the point of the OP. He wants to throw 404 instead of echoing “Not Found” in the template’s “Else” case.

    From what I’ve seen so far, it looks like this can only be done at the top of the template before any whitespace and before get_header(). The template has to call has_posts() and then handle the 404 manually by setting headers, including other templates, and quitting the script.

    Robert Chapin

    (@miqrogroove)

    For example, at the top of archive.php, get rid of this:
    <?php get_header(); ?>

    Replace with this:

    <?php
    if (!have_posts()) {
        header("HTTP/1.0 404 Not Found - Archive Empty");
        require TEMPLATEPATH.'/404.php';
        exit;
    }
    get_header();
    ?>

    NOW you have proper SEO. It’s shocking to see the WordPress core miss things like that.

    This works a little better:

    <?php
    if (!have_posts()) {
        header("HTTP/1.0 404 Not Found - Archive Empty");
        $wp_query->set_404();
        require TEMPLATEPATH.'/404.php';
        exit;
    }
    get_header();
    ?>

    miqrogroove

    Yes, you are absolutely correct. We use it like this:

    if(have_posts())
    {
    .. do something
    }
    else
    {
    include(TEMPLATEPATH . ‘/404.php’);
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘envoke 404 manualy’ is closed to new replies.