WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Confused about file names: searchform, Search Form and search_form (4 posts)

  1. La M
    Member
    Posted 5 years ago #

    I'm a bit confused about the various names that php template files seem to have.

    For example,

    1) my search form's file name is "searchform.php", but in the Appearance > Editor > Template list it also has a name of "Search Form".
    2) And when you want to include it into somewhere such as the sidebar, you call it "search_form", as in <?php get_search_form(); ?>

    Where do these alternative names come from?

    I've created a new newsletter subscription form called "subscribeform.php". I'd also like to give it a plain English name and include it in my sidebar.php. How do I do this?

    Thanks

  2. Michael Fields
    Themer
    Posted 5 years ago #

    1) my search form's file name is "searchform.php", but in the Appearance > Editor > Template list it also has a name of "Search Form".

    "searchform.php" is the name of the php file as it is viewed by the file system on your server. "Search Form" is a title that the Template Editor gives to the aforementioned file. Basically, "Search Form" is a human readable version of the filename.

    2) And when you want to include it into somewhere such as the sidebar, you call it "search_form", as in <?php get_search_form(); ?>

    get_search_form() is what is known a a Template Tag which is basically a php function that allows you display different parts of your blog in various different templates. This Template Tag looks for a file called searchform.php in your current theme's directory and if it finds it, it will include this file in the template. If the file is not found , it will print a default version of a search form to the screen.

    Where do these alternative names come from?

    I think they are just there to confuse new users:)

    I've created a new newsletter subscription form called "subscribeform.php". I'd also like to give it a plain English name and include it in my sidebar.php. How do I do this?

    Not sure about giving it a Plain English name, but it is rather easy to include into your sidebar. First, upload subscribeform.php to your server - into your current theme's directory. Next, open your sidebar.php file in a text editor and add the following code in the spot where you would like the form to appear:

    include( TEMPLATEPATH . '/subscribeform.php' );

    If your theme is widget enabled, you will want to put this bit of code outside of the "widget conditional"... it looks something like this:

    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

    Best of luck to ya!

  3. La M
    Member
    Posted 5 years ago #

    Thanks mfields

    So just curious, but can you explain why the template tag calls <?php get_search_form(); ?> with the hyphen when the file itself is searchform.php without a hyphen?

  4. Michael Fields
    Themer
    Posted 5 years ago #

    Absolutely no idea... it's just a name after all :)

Topic Closed

This topic has been closed to new replies.

About this Topic