• Is this possible?

    I’ve used the template hierarchy to display a custom template when looking at the Category page for all the “Press” posts. But clicking on an individual post still loads the single.php template. I’d like WordPress to display the custom template if that Single Post is in the “Press” category and the default Single.php template if it is anything else.

    Could someone point me in the right direction of figuring this out? I’ve been reading about conditional tags and Category templates for a while but I feel even more confused. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter gmisen

    (@gmisen)

    I tried doing an if statement, but it wrecks my page. Is my syntax wrong? I want it to display this code instead of the sidebar if the Single Post is in a Certain Category (66, 67 or 68) but to just load the normal sidebar if the post is in any other category.

    What am I doing wrong?

    This is what I tried, at the bottom of the page, after the post is listed:

    <?php endwhile; else: ?>
    
    <p>Sorry, no posts matched your criteria.</p>
    
    <?php endif; ?>
    
    </div>
    
    <?php if( is_category(array(66,67,68)) {echo '<div id="presssidebar"><p class="about_person_name">Press Room</p>
    <p class="namendate2">Welcome to the NileGuide press room.  We've compiled information about NileGuide that we hope you’ll find helpful. If you’d like further information about NileGuide, to set up an interview with NileGuide's CEO, or to see a demo of our site, please contact us via the information below.</p>
    <p><ul><li><a href="#company description">What We Do</a></li><li><a href="#timeline">History/Timeline</a></li><li><a href="#pressreleases">Press Releases</a></li><li><a href="#inthenews">In The News…</a></li><li><a href="https://www.nileguide.com/pages/team.html">The Team and Board of Directors</a></li>
    <li><a href="https://blog.nileguide.com">NileGuide Blog</a></li></ul></p>
    <p><b>Kirstin Hornby</b><br />Director of Marketing<br /><a href="mailto:[email protected]">[email protected]</a><br />650-636-9369 x110</p>
    </div>'; } else {get_sidebar();} ?>
    
    <?php get_footer(); ?>
    Thread Starter gmisen

    (@gmisen)

    I tried doing an if statement, but it wrecks my page. Is my syntax wrong? I want it to display this code instead of the sidebar if the Single Post is in a Certain Category (66, 67 or 68) but to just load the normal sidebar if the post is in any other category.

    What am I doing wrong?

    This is what I tried, at the bottom of the page, after the post is listed:

    <?php endwhile; else: ?>
    
    <p>Sorry, no posts matched your criteria.</p>
    
    <?php endif; ?>
    
    </div>
    
    <?php if( is_category(array(66,67,68)) {echo '<div id="presssidebar"><p class="about_person_name">Press Room</p>
    <p class="namendate2">Welcome to the NileGuide press room.  We've compiled information about NileGuide that we hope you’ll find helpful. If you’d like further information about NileGuide, to set up an interview with NileGuide's CEO, or to see a demo of our site, please contact us via the information below.</p>
    <p><ul><li><a href="#company description">What We Do</a></li><li><a href="#timeline">History/Timeline</a></li><li><a href="#pressreleases">Press Releases</a></li><li><a href="#inthenews">In The News…</a></li><li><a href="https://www.nileguide.com/pages/team.html">The Team and Board of Directors</a></li>
    <li><a href="https://blog.nileguide.com">NileGuide Blog</a></li></ul></p>
    <p><b>Kirstin Hornby</b><br />Director of Marketing<br /><a href="mailto:[email protected]">[email protected]</a><br />650-636-9369 x110</p>
    </div>'; } else {get_sidebar();} ?>
    
    <?php get_footer(); ?>
    Thread Starter gmisen

    (@gmisen)

    I tried doing an if statement, but it wrecks my page. Is my syntax wrong? I want it to display this code instead of the sidebar if the Single Post is in a Certain Category (66, 67 or 68) but to just load the normal sidebar if the post is in any other category.

    What am I doing wrong?

    This is what I tried, at the bottom of the page, after the post is listed:

    <?php endwhile; else: ?>
    
    Sorry, no posts matched your criteria.
    
    <?php endif; ?>
    
    </div>
    
    <?php if( is_category(array(66,67,68)) {echo '<div id="presssidebar"><p class="about_person_name">Press Room
    
    <p class="namendate2">Welcome to the NileGuide press room.  We've compiled information about NileGuide that we hope you’ll find helpful. If you’d like further information about NileGuide, to set up an interview with NileGuide's CEO, or to see a demo of our site, please contact us via the information below.
    
    <ul><li><a href="#company description">What We Do</a></li><li><a href="#timeline">History/Timeline</a></li><li><a href="#pressreleases">Press Releases</a></li><li><a href="#inthenews">In The News…</a></li><li><a href="https://www.nileguide.com/pages/team.html">The Team and Board of Directors</a></li>
    <li><a href="https://blog.nileguide.com">NileGuide Blog</a></li></ul>
    
    <b>Kirstin Hornby</b>Director of Marketing<a href="mailto:[email protected]">[email protected]</a>650-636-9369 x110
    
    </div>'; } else {get_sidebar();} ?>
    
    <?php get_footer(); ?>

    Was this ever resolved? I am wondering the same.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display a Different Template for a Single Post IF its in a certain Category’ is closed to new replies.