Ready to get started?Download WordPress


Sidebar (default) - PHP question (9 posts)

  1. moshu
    Posted 9 years ago #

    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?

  2. Kafkaesqui

    Posted 9 years ago #

    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; ?>

  3. Kafkaesqui

    Posted 9 years ago #

    In case anyone is wondering:

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

  4. moshu
    Posted 9 years ago #

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

  5. moshu
    Posted 9 years ago #

    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?

  6. Kafkaesqui

    Posted 9 years ago #

    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?

  7. moshu
    Posted 9 years ago #

    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?

  8. Kafkaesqui

    Posted 9 years ago #

    Ok, back to elegant:

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

  9. moshu
    Posted 9 years ago #

    Starting to love PHP... too bad I don't know it. LOL

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.