WordPress.org

Ready to get started?Download WordPress

Forums

Redirecting from single.php page (3 posts)

  1. bartman316
    Member
    Posted 7 years ago #

    Hello,

    I would like for various single pages to be redirected from the original single.php page. In other words I would like entries from Category 1 to be placed into single1.php, Category 2 entries to be placed into single2.php and so on.

    I found the following, when placed in my single.php somewhat works:

    <?php
    $post = $wp_query->post;
    if ( in_category('2') ) {
    include(TEMPLATEPATH . '/single2.php');
    }
    if ( in_category('3') ) {
    include(TEMPLATEPATH . '/single3.php');
    }
    if ( in_category('4) ) {
    include(TEMPLATEPATH . '/single4.php');
    }
    else {
    include(TEMPLATEPATH . '/single1.php');
    }
    ?>

    The only problem is that on the entries in single2, single3, single4, the post seems to repeat. The page will look as I want it but following the footer, the page will repeat itself in the single1.php format additionally.

    Anything that falls under the 'else' statement works fine and everything that is under the 'if' statement works, but is followed by a duplicate entry in this single1.php format.

    Can anyone help me with the syntax here. It doesn't seem like it should be that complicated but I'm having some trouble getting it to work. Thanks!

  2. Kafkaesqui

    Posted 7 years ago #

    Your problem is the logic in your if/else statements. You'll need to combine it all as one statement block using elseif:

    if () {
    ...
    } elseif () {
    ...
    } elseif () {
    ...
    } else {
    ...
    }

    Note: I offer a plugin solution for what you're attempting here:

    http://guff.szub.net/2005/07/21/post-templates-by-category/

  3. bartman316
    Member
    Posted 7 years ago #

    Thanks! I knew it was something simple.

Topic Closed

This topic has been closed to new replies.

About this Topic