• Resolved jkozuch

    (@jkozuch)


    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:

    <code>is_page('2,3,5')</code

    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.

    Thanks,

    Justin

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’m probably missing the obvious, but why not just do multiple Page Templates?

    Thread Starter jkozuch

    (@jkozuch)

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

    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.

    Thread Starter jkozuch

    (@jkozuch)

    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.

    Thread Starter jkozuch

    (@jkozuch)

    I figured it out.

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

    <?php
    /*
    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;
    '); ?>
    </div>
    </div>
    <?php endwhile; endif; ?>
    </div>
    <?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-->
    <?php
    // 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-->
    </div>
    </div>

    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.

    Rock on – glad you got it all sorted out. ??

    Mark this topic as [Resolved] at the top?

    Happy blogging!

    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)) {
    
    whatever
    
    }
    else ....

    to add the same thing for multiple pages.

    hth

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conditional Tags Feature Request’ is closed to new replies.