• Hi,

    I’m making a new WP theme, my first ever (called Xpress), and wanted to include a search bar right at the top.

    I made a file searchform.php which has the code to display the bar.

    But when i call my bar at the header file where i want:

    <?php include (TEMPLATEPATH . ‘/searchform.php’); ?>

    I get an error on that space in my header. The error reads:

    Warning: Division by zero in C:\xampp\htdocs\wordpress\wp-content\themes\Xpress\header.php on line 121
    
    Warning: include(C:\xampp\htdocs\wordpress/wp-content/themes/Xpressphp’) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\wordpress\wp-content\themes\Xpress\header.php on line 121
    
    Warning: include() [function.include]: Failed opening 'C:\xampp\htdocs\wordpress/wp-content/themes/Xpressphp’' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\wordpress\wp-content\themes\Xpress\header.php on line 121

    What wrong am i doing here? Isn’t the calling function correct? Have i goofed up in forward/backward slashes (/ or \)?

    Please help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • First, you need to use the proper template include tag. For including the Search Form, you should use:

    <?php get_search_form(); ?>

    Second, if you don’t need to modify the default Search Form markup, then you don’t need to include “searchform.php”, as the get_search_form() template tag will use the default markup if no “searchform.php” is included in the Theme.

    Third: the specific problem you’re having appears to be an issue with your local test environment. Note the specified filepath:

    C:\xampp\htdocs\wordpress/wp-content/themes/Xpressphp

    See what’s wrong? Your slashes change direction.

    Nevertheless: simply get rid of “searchform.php”, call the search form using get_search_form(), and you should be fine.

    Thread Starter firstain

    (@firstain)

    “Third: the specific problem you’re having appears to be an issue with your local test environment. Note the specified filepath:”

    What could be the cause of this problem? How did it occur? How to solve it now?

    Thanks for get_search_form()

    Thread Starter firstain

    (@firstain)

    Hi,

    i tried using <?php get_search_form(); ?> and instead of showing my search bar, it just displayed the code of the file.

    Code of my searchform.php file:

    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <div><input type="text" value="<?php if(is_search() ) { the_search_query(); } else { echo 'Search...'; } 
    
    ?>" name="s" id="s" onfocus="if(this.value=='Search...')this.value='<?php the_search_query(); ?>'" 
    
    onblur="if(this.value=='')this.value='Search...'" />
    <input type="submit" id="searchsubmit" value="Search" />
    </div>
    </form>

    I called this in my header file. Instead of search bar, it showed this on my theme:

    ??<?form method="get" id="searchform" action="<??php bloginfo('url'); ?>/"> <?div><?input type="text" value="<??php if(is_search() ) { the_search_query(); } else { echo 'Search...'; } ?>" name="s" id="s" onfocus="if(this.value=='Search...')this.value='<??php the_search_query(); ?>'" onblur="if(this.value=='')this.value='Search...'" /> <?input type="submit" id="searchsubmit" value="Search" /> <?/div> <?/form>

    What’s happening? What are these strange question marks that appear?

    I then removed the searchform.php file from my directory and refreshed the page and voila! The search bar with a search button next to it appeared. But the problem is i don’t like the default search form. I want to style my own form and have other effects. What and how to do?

    I also have a modified search.php file.

    What to do now?

    Do you have some improperly closed PHP tags somewhere in your template files?

    EDIT: also, do you have some non-printable characters in your template files?

    (Also: the “search.php” template file displays the results of a search query; it should have no bearing on your issue.)

    Thread Starter firstain

    (@firstain)

    As far as i’m concerned, i have no ‘improperly closed PHP tags’and no ‘non-printable characters’ anywhere in my template files.

    But still, just for reassurance, how do i check for the above mentioned errors? Obviously i can’t go through so much of codes in all my files manually, so is there a quick way to find out and check for them?

    P.S. If there were improperly closed tags or something, then my theme wouldn’t work, right? But its working. Its only when i include my search form that it shows an error.

    Thread Starter firstain

    (@firstain)

    One more thing…

    All the posts listed in my theme are working perfectly, apart from one post: https://localhost/wordpress/2008/09/05/readability-test/

    It was working properly before but now, when i open that page, only the header file loads, breadcrumb is broken, and no sidebar and footer. It shows the following error:

    Catchable fatal error: Object of class WP_Error could not be converted to string in C:\xampp\htdocs\wordpress\wp-content\themes\Xpress\functions.php on line 385

    Line 385 on my functions.php is this:

    echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');

    This line 385 is the code for breadcrumbs. What could be the error?

    Is this breadcrumb issue on only 1 particular post problem in any way related to my search form problem?

    Please help!
    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Help with Searchform.php’ is closed to new replies.