• Resolved Arteaster

    (@arteaster)


    Hello !

    I want to set up a SearchForm

    on:

    if ( is_archive() || is_category() || is_search())

    between header and container, or as first item in container before all content.

    The hierarchy would be:

    <header class=”masthead …

    <header class=”landmark …

    SearchForm

    <div class=”container …`

    or

    <div class=”container …`

    – SearchForm –

    Content of container

    searchform.php template exist

    Thanks in advance !

    • This topic was modified 2 years, 2 months ago by Arteaster.
    • This topic was modified 2 years, 2 months ago by Arteaster.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    Many themes actually open the post container within header.php, which is included from whatever principal template is being used. So header.php is likely where you would insert the form code, but YMMV.

    After your conditional statement just add { include searchform.php; }. Place the entire thing where you wish on your header.php template.

    If your theme is subject to periodic updates, you should create a child theme to contain your modified template file. Otherwise updates will wipe out your changes.

    Thread Starter Arteaster

    (@arteaster)

    @bcworkz

    Thanks for your response

    Your suggest may be useful, but I need seaarchform only on archive pages

    Something like:

    if ( is_archive() || is_category() || is_search())

    Moderator bcworkz

    (@bcworkz)

    After your conditional statement just add { include searchform.php; }

    Like this:
    if ( is_archive() || is_category() || is_search()) { include searchform.php; }

    Thread Starter Arteaster

    (@arteaster)

    I guess a different script form is needed and/or full path to searchform.php template, because this what I get:

    https://images2.imgbox.com/2b/5d/YIaQ0V0G_o.jpg

    ===

    <?php get_search_form(); ?>

    works fine but that’s not theme searchform.php template`

    • This reply was modified 2 years, 2 months ago by Arteaster.
    Moderator bcworkz

    (@bcworkz)

    Argh! My bad, I forgot to include quotes.
    if ( is_archive() || is_category() || is_search()) { include 'searchform.php';}

    I’m assuming the templates both lie in the same folder. Also, some versions of PHP require absolute paths to files. If either are an issue for you, one of these should work:
    if ( is_archive() || is_category() || is_search()) { include get_stylesheet_directory() . '/searchform.php';} // same folder

    if ( is_archive() || is_category() || is_search()) { include get_stylesheet_directory() . '/template-parts/searchform.php';} // some other folder

    Aside from my error, it’s strange for the include statement to be output as text. Are there any intervening <?php ?> tags that shouldn’t be there? Without the quotes you should have either gotten nothing or error messaging, depending on your PHP error reporting configuration.

    Thread Starter Arteaster

    (@arteaster)

    @bcworkz

    Thanks a lot !

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘SearchForm between header and archive container’ is closed to new replies.