[resolved] Conditional Tags Feature Request (8 posts)

  1. jkozuch
    Posted 9 years ago #

    I don't know if this has been posted before, but it would be nice to have the conditional tags extended a bit.

    For instance, I have a series of pages that use a parent page on my website.

    I also conditional logic to create variable sidebar content, which has been an absolute godsend for me. It's one of my favorite features of WordPress functionality.

    However, it's somewhat lacking, as I need to create a different if statement for each page if I want to display content, even if the content for 2 or more pages will be the same. This is somewhat of a pain, and if I need to update the content for these 2 pages, I need to do it in 2 or more places.

    Basically, it would be really nice if you could have:


    It would be even better to have this idea extended to is_single, is_category, is_author, is_pages, and is_attachment.

    I'm planning on standarding many of my client's website on WordPress, so except many more of these suggestions as I go through the paces.



  2. Chris_K
    Posted 9 years ago #

    I'm probably missing the obvious, but why not just do multiple Page Templates?

  3. jkozuch
    Posted 9 years ago #

    I don't know much about that, but isn't sorta the same thing? Pardon my ignorance LOL.

  4. Chris_K
    Posted 9 years ago #

    Well, if your goal is to have variable/differing content on assorted Pages... instead of using conditional tags and a common Page template, just create multiple Page templates, each with the necessary/desired customizations.

    See the Pages link for more, section 7 discusses templates.

    Hope that helps.

  5. jkozuch
    Posted 9 years ago #

    So let's say that I have six child pages for the portfolio category, I create a template called client.php and use that template for each of the pages under portfolio. Then, I use that instead of the if statement. That's how I understood that link you sent.

  6. jkozuch
    Posted 9 years ago #

    I figured it out.

    What I did was create a template called client.php, and inserted this code:

    Template Name: Client
    <?php get_header(); ?>
    <div id="content">
    <div id="contentLeft">
    <?php if (have_posts()) : while (have_posts()) : the_post();?>
    <div class="post">
    <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
    <div class="entrytext">
    <?php the_content('<p class="serif">Read the rest of this page &raquo;
    '); ?>
    <?php endwhile; endif; ?>
    <?php include ('sidebar-client.php'); ?>
    <?php get_footer(); ?>

    Then I created a file called sidebar-client.php, and inserted this code:

    <div id="sidebar">
    <div id="contentRight">
    <!--first/center column-->
    // portfolio page/sub-pages
    if (is_page()) {
    echo '<h4>Noteworthy Notes</h4>
    These examples are a small smattering of both my personal and professional work in recent years.
    Feel free to read more <a href="/about/" title="About Me">about me</a> or <a href="/wp-content/docs/justinkozuchresume.pdf" onclick="javascript:urchinTracker(/downloads/resume/);" title="My CV">download my CV</a> for my career history.
    '; }
    // That's all, folks!
    <!--first/center column-->

    I edited all the pages for the portfolio items to use the template called client and was able to consolidate my custom sidebar into those pages, using 1 conditional, and not 6 like I was doing before. Easy peasy. Thanks Handy.

  7. Chris_K
    Posted 9 years ago #

    Rock on - glad you got it all sorted out. :-)

    Mark this topic as [Resolved] at the top?

    Happy blogging!

  8. syncbox
    Posted 8 years ago #

    but just so you know... and when you don't want a custom page template, you can use conditional code like so:

    if (is_page(3) || is_page(4) || is_page(11)) {
    else ....

    to add the same thing for multiple pages.


Topic Closed

This topic has been closed to new replies.

About this Topic