Examples of PHP functions used to create and get sidebar in WordPress

Source: Internet
Author: User
Tags php language php and mysql
WordPress is a blog platform developed using the PHP language that allows users to build their own websites on servers that support PHP and MySQL databases. WordPress can also be used as a content management system (CMS) to use.

WordPress is a personal blog system, and gradually evolved into a content management system software, which is developed using the PHP language and MySQL database. Users can use their own blogs on servers that support PHP and MySQL databases.

WordPress has a number of third-party developed free templates, easy to use installation methods. But to make a template of your own, you need to have a certain degree of expertise. For example, you should know at least one of the standard universal markup languages, the application of HTML code, CSS, PHP and other related knowledge.

WordPress Official support Chinese version, while there are enthusiasts to develop a third-party Chinese language pack, such as Wopus Chinese language pack. WordPress has thousands of plugins and countless theme template styles. [

This article mainly introduces the PHP functions used to create and get sidebar in WordPress, respectively, the use of Register_sidebar () function and Get_sidebar (), the need for friends can refer to the following

Register_sidebar () (Create sidebar)
Create a sidebar that you can use to place small tools. When this function is used, please 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 be created.

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 ' = ' 

Array parameter Description:

    • Name: Side bar Names

    • ID: Side bar ID, must be lowercase, increment array ID by default

    • Description: Side Bar Description

    • Class: An extra class to the gadget

    • Before_widget: The opening of the gadget inside the Html code

    • After_widget: Html code at the end of the gadget inside

    • Before_title: Html code at the beginning of the title of the gadget inside

    • After_title: Html code at the end of the title of the gadget inside

Example

Register_sidebar (  ' name '     = = (' Right side sidebar '),  ' id '      = ' sidebar-1 ',  ' description ' = ( ' Widgets on the right sidebar. '),  ' before_title ' = ' 

Other

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

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

Usage

Get_sidebar ($name);

Parameters

$name

(string) (optional) introduces the name of the template and, if specified, the sidebar-{$name}.php file that introduces the root of the current theme.

Default value: None

Example

The following code introduces the sidebar.php file to the root of the current theme:

<?php Get_sidebar ();?>

The following code introduces the sidebar-left.php file to the root of the current theme:

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

The following example introduces the left sidebar (sidebar-left.php) and the right sidebar (sidebar-right.php), respectively:

<?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.