• Resolved wethead

    (@wethead)


    Hello

    I am trying something new ( To Me at least )

    I am trying to get a DIFFERENT single php template to show when I add this code, BUT for some reason, its not working for me,

    The “else” seems to work , meaning : when I run this code , ALL the other pages show my “single1.php”

    BUT my PROBLEM is the cat “762” ALSO shows the single1.php 🙁

    Can someone tell me what I am doing wrong PLEASE 🙂 ( with sugar and cherries )

    I am trying to apply the following: ( This is placed in my single.php )

    <?php
    $post = $wp_query->post;
    if ( in_category(‘762’) ) {
    include(TEMPLATEPATH . ‘/lpsingle.php’);
    } else {
    include(TEMPLATEPATH . ‘/single1.php’);
    }
    ?>

    ANY help all all would be great 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • Me too,
    if u have any ways to solve it
    please contact me
    Ths!
    MSN: xiaoniao8880@Gmail.com

    No, Spider110, that’s not how it works. Solutions, if any, will be posted to this forum for the benefit of EVERYONE here. If you want the information, it’s incumbent upon YOU to come here to find out if a solution has been posted, it’s not up to anyone here to chase you down with the answer. It’s against the spirit of a forum, you know? 🙂

    @wethead: What exactly are you trying to do? Are you trying to set up a particular post or category to pull a particular template? If so, you may be overthinking things here. Let me know.

    Oh,jonimueller
    thank you for reminding!
    I just want to solve the problem!
    No other meaning!

    Now ,is anyone have some ways to solve it?

    Is it not because the if is looking for a file called lpsingle.php?

    Shouldn’t it read:

    <?php
    $post = $wp_query->post;
    if ( in_category('762') ) {
    include(TEMPLATEPATH . '/single.php');
    } else {
    include(TEMPLATEPATH . '/single1.php');
    }
    ?>

    Just a thought

    I think you have to use the following code in your single.php
    ‘<?php
    if ( have_posts() ) { the_post(); rewind_posts(); }
    if ( in_category(762) ) {
    include(TEMPLATEPATH . ‘/single2.php’);
    } else {
    include(TEMPLATEPATH . ‘/single1.php’);
    }
    ?>’
    Only this code – no loop – and then you have to create single1.php and single2.php.

    Thread Starter wethead

    (@wethead)

    Hi Everyone.

    I am actually using wordpress as a CMS system.

    I have found MANY cool code hacks on codex 🙂

    I am replacing my cat pages using the standard wordpress cat-789.php example 🙂

    So what I am looking to do is have a DIFFERENT single php show up on certain posts that are in a certain category.

    @the above comment, YES, I do realize that I had single.php and On my server I had the code right.

    I also understand that I need the loop but that is what the single1.pho and the single2.php are for,

    So in a nut shell I want to use the above code to show a separate or different single php for the categories I code ( above code )

    What I am trying to so is listed here

    Query-based Templates

    WordPress can load different Templates for different query types. There are two ways to do this: as part of the built-in Template Hierarchy, and through the use of Conditional Tags within The Loop of a template file.

    To use the Template Hierarchy, you basically need to provide special-purpose Template files, which will automatically be used to override index.php. For instance, if your Theme provides a template called category.php and a category is being queried, category.php will be loaded instead of index.php. If category.php is not present, index.php is used as usual.

    You can get even more specific in the Template Hierarchy by providing a file called, for instance, category-6.php — this file will be used rather than category.php when generating the page for the category whose ID number is 6. (You can find category ID numbers in Manage > Categories if you are logged in as the site administrator). For a more detailed look at how this process works, see Category Templates.

    If your Theme needs to have even more control over which Template files are used than what is provided in the Template Hierarchy, you can use Conditional Tags. The Conditional Tag basically checks to see if some particular condition is true, within the WordPress Loop, and then you can load a particular template, or put some particular text on the screen, based on that condition.

    For example, to generate a distinctive style sheet in a post only found within a specific category, the code might look like this:

    <?php
    if (is_category(9)) {
    // looking for category 9 posts
    include(TEMPLATEPATH . ‘/single2.php’);
    } else {
    // put this on every other category post
    include(TEMPLATEPATH . ‘/single1.php’);
    }
    ?>

    Or, using a query, it might look like this:

    <?php
    $post = $wp_query->post;
    if ( in_category(‘9’) ) {
    include(TEMPLATEPATH . ‘/single2.php’);
    } else {
    include(TEMPLATEPATH . ‘/single1.php’);
    }
    ?>

    In either case, this example code will cause different templates to be used depending on the category of the particular post being displayed. Query conditions are not limited to categories, however — see the Conditional Tags article to look at all the options.

    Thanks in advance!

    Thread Starter wethead

    (@wethead)

    @jbrndt

    I will try this , But it seems this is from 2005

    I wonder if it will work with the laster version, 🙂

    I will report back 😉

    Thanks !

    Thread Starter wethead

    (@wethead)

    @jbrndt

    That last post was the GOLDEN TICKET!!!

    Thanks so much man!

    Issue Resolved 🙂

    You’re welcome. I use it all the time.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Help with double single php’s’ is closed to new replies.