This article describes how to obtain the header template and the bottom template in the WordPress topic writing, including the use of the get_header () and get_footer () functions. For more information, see
Get_header () (obtain the header)
Introduce the header template of the topic. by default, the header. php file in the current topic directory is introduced. If a name is specified, the header-{name} of the current topic directory is introduced }. php file. if the file to be introduced does not exist, introduce wp-nodes des/theme-compat/header. php file.
Usage
get_header( $name );
Parameters
$ Name
(String) (optional) name of the file to be introduced. if specified, the header-{$ name}. php file is introduced.
Example
<?php get_header(); ?>
The above code will introduce the header. php file in the root directory of the current topic.
<?php get_header( 'main' ); ?>
The code above introduces the header-main.php file of the current topic root directory.
if( is_home() ) get_header( 'home' );elseif( is_404() ) get_header( '404' );else get_header();
The code above will introduce the header-home.php file for the current topic root directory on the home page, page 404 will introduce the header-404.php file for the current topic root directory, other pages will introduce the header. php file for the current topic root directory.
Others
This function is located in: wp-des/general-template.php
Get_footer () (get the bottom)
Get_footer () is used to introduce the bottom template file. If the name is specified, the footer-{name} of the root directory of the current topic is introduced }. php file. if not specified, the footer of the root directory of the current topic will be introduced. php file. if the file does not exist, introduce wp-nodes des/theme-compat/footer. php file.
Usage
get_footer( $name );
Parameters
$ Name
(String) (optional) name of the imported template. if specified, the footer-{$ name}. php file is introduced.
Return value
This function has no return value.
Example
Introduce the footer. php file in the root directory of the current topic:
<?php get_footer(); ?>
Introduce the footer-new.php file for the current topic root directory:
<?php get_footer( 'new' ); ?>
Introduce different bottom template files based on different pages:
If (is_404 () get_footer ('20140901'); // if the page is 404, introduce the footer-404.php file elseif (is_home () for the root directory of the current topic ()) get_footer ('Home'); // if it is the home page, introduce the footer-home.php file else get_footer () for the root directory of the current topic (); // if it is not the home page or 404 page, the footer of the root directory of the current topic will be introduced. php files
Others
This function is located in: wp-des/general-template.php