• I’m modifying the default theme (in 1.5.2) to use different single.php for a couple of categories. However, when I view a post in that category, I get the post as expected but under the footer I get this: “Sorry, no posts matched your criteria” and the sidebar repeats (but not the footer).

    This only happens on posts, not on Pages, archives, search.

    Is there something in single.php I need to remove to get this doubling up taken care of?

    My single.php is this:

    <?php
    $post = $wp_query->post;
    if ( in_category('1') ) {
    include(TEMPLATEPATH . '/singleone.php'); }
    if ( in_category('2') ) {
    include(TEMPLATEPATH . '/singletwo.php'); }
    else {
    include(TEMPLATEPATH . '/singledefault.php');
    }
    ?>

    And my singleone.php etc have all the same code as the default single.php, slightly altered, i.e.
    <div id="content" class="narrowcolumn">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    ----snip---
    <div class="post" id="post-<?php the_ID(); ?>">
    ---snip---
    <?php comments_template(); ?>

    <?php endwhile; else: ?>

    Sorry, no posts matched your criteria.

    <?php endif; ?>

    </div></div>
    <?php include (TEMPLATEPATH . '/sidebarsingle.php'); ?>
    <?php get_footer(); ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The logic of your code in single.php is a little off:

    <?php
    $post = $wp_query->post;
    if ( in_category('1') ) {
    include(TEMPLATEPATH . '/singleone.php'); }
    elseif ( in_category('2') ) {
    include(TEMPLATEPATH . '/singletwo.php'); }
    else {
    include(TEMPLATEPATH . '/singledefault.php');
    }
    ?>

    Note the change to elseif in the second block. You also shouldn’t need the $post = $wp_query->post;

    Anyway, you may be interested in a plugin of mine:

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

    Thread Starter silverwing

    (@silverwing)

    the ‘elseif’ is what I needed.

    thanks, everyone.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘singleX.php using is_single doubling up’ is closed to new replies.