Getting the header template and the bottom template _ php skills in WordPress topic writing

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.