• Hopefully this one won’t be too challenging. I want the Loop to do it’s normal thing (that I finally figured out) of giving only excerpts on the main page, categories, and archives, and when a single post is requested, it uses the single.php template, which looks different from the index.php, category.php, and archives.php. And of course, I want to make this more difficult.

    How would the Loop be formatted to add a condition that says:

    IF category 17, use single2.php and not single.php

    I have a category of pages that require massive amounts of unique CSS (trying to convert my popular css experiments to fit within WordPress) and I don’t want to load them up in the style.css and I really don’t want these to be in Pages because they I have to mess around with making sure that these pages show up on the categories and archives in a special way because they aren’t part of the Loop.

    If there is a better way to do this, I’m game. The style sheet for these experiments is huge.

Viewing 13 replies - 16 through 28 (of 28 total)
  • I created a Custom post template plugin to make this easier.

    Thread Starter Lorelle

    (@lorelle)

    So it’s customizable by post ID and not just category. That’s really customization. I love it. Most brilliant.

    Thanks!

    OK. I think this is a good idea.

    So, tell me steps by steps how Lorelle figured it out. Would you? I am confusing all the sayings. Thanks

    Just Use ryan’s plugin referenced above.

    Someone’s also working on a Post Templates Plugin that provides post templates in the same fashion that core WP provides page templates.

    Thread Starter Lorelle

    (@lorelle)

    nden, did you figure it out?

    Hello! I am very glad having found this helpful thread!

    I had the same problem as Lorelle had and follow this here curiously. The way of putting this “template switch” in the single.php manually works very well. But unfortunately I can’t bring ryan’s plugin to work.

    I get this error message 4 times and the custom templates don’t show up after:
    Warning: Invalid argument supplied for foreach() in /home/www/htdocs/neoflox.net/page/wp-includes/template-functions-category.php on line 410

    Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/www/htdocs/neoflox.net/page/wp-includes/template-functions-category.php on line 414

    I have the right files in the template directory and I believe I configered the plugin properly:

    if ( in_category(‘1’) && file_exists(TEMPLATEPATH . ‘/single-1.php’) )
    return TEMPLATEPATH . ‘/single-1.php’;
    if ( in_category(‘2’) && file_exists(TEMPLATEPATH . ‘/single-2.php’) )
    return TEMPLATEPATH . ‘/single-2.php’;

    PLEASE be so kind and help me out you wonderful people! ??

    Thread Starter Lorelle

    (@lorelle)

    I got this to work without the plugin. The code ended up being like this inside of a file called single.php with NOTHING else in that file:

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

    I then created single1.php and a single2.php with different style sheets and headers and even sidebars, since I can put whatever I wanted in each one. This is brilliant and no stress at all. No plugin no nothing.

    I’m sure you can make a series of these in the single.php that asks if X then single4.php or single6.php and so on.

    I hope this helps.

    Oh this is a great thread. I am helping a friend set up her blog so that one category is totally different, and we figured that out, but I hadn’t yet thought about how they would appear when viewed as single. Looks all too easy now. ??

    Just to complicate the issue, I also put together a plugin for this:

    https://www.ads-software.com/support/topic.php?id=27821#post-156289

    Well, Lorelle, thanks, but that was the way it always worked for me ?? Now I asked how to make the plugin work ??

    hi, i’m new in WP. I’ve installed WP and works fine. My blog has two authors, and when a single page is requested, I want the loop to action: if the author is admin, use single1.php and if the author is Tedy, use single2.php. So I have similar problem except I want to sort it by author. I tried to change the above code into:

    <?php
    $post = $wp_query->post;
    if ( is_author('Soyuz') ) {
    include(TEMPLATEPATH . '/single2.php');
    } else {
    include(TEMPLATEPATH . '/single1.php');
    }
    ?>

    It didn’t work. It always shows the single1.php

    Any suggestion?

    Thanks.

    I’d love to use Ryan’s plugin but instead of customizing the template by category and post_id I’d like to use it for author_id. Is that possible? I’ve tried noodling around with it, but I’m afraid I just don’t know enough. Any help would be appreciated. Thanks!

Viewing 13 replies - 16 through 28 (of 28 total)
  • The topic ‘Have a second single.php file for different single post look?’ is closed to new replies.