WordPress Theme Writing to get the head template and the bottom template _php tips

Source: Internet
Author: User

Get_header () (Get head)
introduces the header template of the theme, which by default introduces the header.php file in the current topic directory. If a name is specified, the header-{name}.php file for the current topic directory is introduced, and the wp-includes/theme-compat/header.php file is introduced if the file you want to introduce does not exist.

Usage

Get_header ($name);

Parameters

$name

(optionally) the name of the file to be introduced and, if specified, the header-{$name}.php file.

Example

<?php Get_header ();?>

The code above will introduce the header.php file in the root of the current topic.

<?php get_header (' main ');?>

The code above will introduce the header-main.php file in the root of the current topic.

if (Is_home ()) Get_header (' home ');
ElseIf (is_404 ()) get_header (' 404 ');
else Get_header ();

The above code introduces the header-home.php file of the current topic root in the first page, 404 pages introduces the header-404.php file of the current topic root, and the other pages introduce the header.php file of the current topic root directory.

Other

This function is located at: wp-includes/general-template.php


Get_footer () (Get bottom)
Get_footer () is used to introduce the bottom template file. If the specified name introduces the footer-{name}.php file of the current topic root, if not specified, the footer.php file is introduced into the current topic root, and if the file does not exist, the wp-includes/theme-compat/ footer.php files.

Usage

Get_footer ($name);

Parameters

$name

(optionally) introduce the name of the template and, if specified, introduce the footer-{$name}.php file.

return value

There is no return value for this function.

Example

Introduce the footer.php file for the current topic root:

<?php Get_footer ();?>

Introduce the footer-new.php file for the current topic root:

<?php get_footer (' new ');?>

Introduce different bottom template files based on different pages:

if (is_404 ()) get_footer (' 404 ');//if 404 pages, introduce the footer-404.php file
elseif (Is_home ()) get_footer (' home ') of the current topic root; /If it is the first page, introduce the footer-home.php file of the current topic root.
else Get_footer ();//If not the first or 404 pages, introduce the footer.php file of the current topic root directory

Other

This function is located at: wp-includes/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.