Support » Fixing WordPress » Sidebar (default) – PHP question

  • In the default 1.5 theme (Kubrick) the sidebar goes like this:
    – calling the search form without any condition
    – series of “if” statements (if category, day, month etc.) do this and that
    – when home and/or page do the rest, too.
    Though I am not a coder, but I can understand that much.

    Here is my question: if I want the searchform to appear ONLY when those first six “if” situations exist, how should go? i.e. NO searchform on home page or Page page 🙂 but in all other situations described by those if… lines.

    Any PHP guru out there?
    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Easiest way is to go into searchform.php, make the first line (i.e. add this):

    <?php if(!is_home() && !is_page()) : ?>

    and the last line:

    <?php endif; ?>

    In case anyone is wondering:

    if(!is_home()) = not home page
    if(is_home()) = home page

    Wow, that’s a simple and elegant solution! Thank you very much!

    It works (almost) perfectly. Almost, because I am an idiot and forgot there is one special page that I really need the searchform to appear on.
    Any thoughts?

    A Page page? A little less elegant solution:

    <?php if(!is_home() && !is_page(#1) && !is_page(#2)) : ?>

    Just add && !is_page(PAGEID#) for each Page you don’t want the search form to appear on. Replace PAGEID# with, well, the Page ID #. You can also use the Page slug ('about-my-blog') or Page title ('About My Blog').

    Pretty cool, huh?

    The other way around… the first code
    <?php if(!is_home() && !is_page()) : ?> was OK, but there is on Page page that has to have the form. I need the searchform on ONE Page page 🙂

    What you are suggesting would mean to add to the code all my new pages whenever I make one?

    Ok, back to elegant:

    <?php if(!is_home() && (!is_page() || is_page(PAGEID#))) : ?>

    Kewl!
    Starting to love PHP… too bad I don’t know it. LOL

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Sidebar (default) – PHP question’ is closed to new replies.