Home > Backend Development > PHP Tutorial > Explanation of PHP functions used to create and obtain sidebars in WordPress, wordpressphp_PHP tutorial

Explanation of PHP functions used to create and obtain sidebars in WordPress, wordpressphp_PHP tutorial

WBOY
Release: 2016-07-12 09:02:02
Original
901 people have browsed it

Explanation of PHP functions used to create and obtain sidebars in WordPress, wordpressphp

register_sidebar() (create sidebar)
Create a sidebar to place widgets. When using this function, please put it in a function and mount it to the "widgets_init" hook.

Usage

register_sidebar( $args );
Copy after login

Parameters

$args

(String | Array) (Optional) Parameters for 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' => '<h2 class="widgettitle">',
  'after_title'  => '</h2>'
);
Copy after login

Introduction to array parameters:

  • name: sidebar name
  • id: sidebar ID, must be lowercase, default is an increasing array ID
  • description: Sidebar description
  • class: additional class for the gadgets in it
  • before_widget: the beginning Html code of the widget inside
  • after_widget: Html code at the end of the widget 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( array(
  'name'     => __( '右边的侧边栏' ),
  'id'      => 'sidebar-1',
  'description' => __( '右侧边栏的小工具。' ),
  'before_title' => '<h3 class="title">',
  'after_title' => '</h3 class="title">',
));
Copy after login

Others

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

get_sidebar() (get sidebar)
get_sidebar() is used to introduce the sidebar template. If the name is specified, the sidebar-{name}.php file in the current theme root directory will be imported. If not specified, the sidebar.php file in the current theme root directory will be imported. If the file does not exist, wp-includes/theme-compat/sidebar.php will be imported. document.

Usage

get_sidebar( $name );
Copy after login

Parameters

$name

(String) (optional) The name of the template to import. If specified, the sidebar-{$name}.php file in the current theme root directory will be imported.

Default value: None

Example

The following code will import the sidebar.php file in the current theme root directory:

<&#63;php get_sidebar(); &#63;>
Copy after login

The following code will import the sidebar-left.php file in the current theme root directory:

<&#63;php get_sidebar( 'left' ); &#63;>
Copy after login

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

<?php get_header(); ?>
<&#63;php get_sidebar( 'left' ); &#63;>
Copy after login

Content content

<&#63;php get_sidebar( 'right' ); &#63;>
<&#63;php get_footer(); &#63;>
Copy after login

Others

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

Articles you may be interested in:

  • Tips for customizing the color scheme of the backend management interface in WordPress
  • Analysis of related functions for sending http requests in WordPress
  • How to set default content in the WordPress post editor
  • Detailed explanation of how to use functions to add and perform actions in WordPress

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1086653.htmlTechArticleExplanation of PHP functions used to create and obtain sidebars in WordPress, wordpressphp register_sidebar() (create sidebar ) Create a sidebar to place widgets. This function makes...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template