WordPress to create and get sidebar PHP functions to explain _php skills

Source: Internet
Author: User

Register_sidebar () (Create sidebar)
Create a sidebar for placing gadgets. When this function is used, put it in a function, and mount it to the "widgets_init" hook.

Usage

Register_sidebar ($args);

Parameters

$args

(String | Array) (optional) The parameters of the sidebar to create.

Default value:

$args = Array (
  ' name '     => __ (' Sidebar name ', ' Theme_text_domain '),
  ' id '      => ' Unique-sidebar-id ',
  ' description '  => ', '
  class '     => ',
  ' before_widget ' => ' <li ', id= '%1 ' class= ' Widget%2 ">",
  ' after_widget ' => ' </li> ',
  ' before_title ' => ' 

Introduction to Array Parameters:

    • Name: Side-side bar names
    • ID: Side bar ID, must be lowercase, default to incremented array ID
    • Description: Side Sidebar description
    • Class: Extra Class for gadgets
    • Before_widget: The beginning of the gadget inside the Html code
    • After_widget: The Html code at the end of the gadget inside
    • Before_title: The opening Html code of the title of the gadget inside
    • After_title: The Html code at the end of the title of the gadget inside

Example

Register_sidebar (
  ' name '     => __ (' Sidebar on right side '),
  ' id '      => ' sidebar-1 ',
  ' description ' = > (' Small tool on the right sidebar. '),
  ' before_title ' => ' 

Other

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

Get_sidebar () (Get side bar)
Get_sidebar () is used to introduce sidebar templates. If the specified name introduces the sidebar-{name}.php file of the current topic root, does not specify a sidebar.php file that introduces the root of the current topic, or if the file does not exist, introduces the wp-includes/theme-compat/ sidebar.php files.

Usage

Get_sidebar ($name);

Parameters

$name

(optionally) to introduce the name of the template, if specified, to introduce the sidebar-{$name}.php file of the current topic root.

Default value: None

Example

The code below will introduce the sidebar.php file for the current topic root:

<?php Get_sidebar ();?>

The code below will introduce the sidebar-left.php file for the current topic root:

<?php Get_sidebar (' left ');?>

The example below introduces the left sidebar (sidebar-left.php) and the right-hand sidebar (sidebar-right.php):

<?php Get_header ();?>
<?php Get_sidebar (' left ');?>

Content content

<?php Get_sidebar (' right ');?>
<?php get_footer ();?>

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.