How to add a navigation menu to the WP website through the wp_list_pages function# Xuelang plan #, how to access QQ browser through WPS

1 year ago (2023-12-07) Chief Editor
7 minutes
three hundred and eleven
zero

Each website has its own navigation menu, such as the head navigation menu, the bottom navigation menu, the side bar navigation menu, and wordpress website is no exception. So, in the development of WordPress website theme template, how can we add the foreground navigation menu to WordPress website? Well, according to my years of development experience, wordpress mainly provides three ways to create navigation menus for wordpress theme development. These three ways will create different navigation functions. Today, let's take a look at the first way to create navigation menus for wordpress websites - page based navigation menus. Here, we will use the function provided by wordpress - wp_list_pages(), which is a function of wordpress page list.

Let's take a look at the wordpress function, wp_list_pages(), and its structure.

wp_list_pages($defaults);

From the above code, we can see that the wp_list_pages() function has only one parameter, which can be of two types, string type or array type. We will introduce this in the following example. In order to understand the value of this parameter, we will explain this parameter in the form of array.

Parameter introduction:

$defaults=array (depth=>0,//0: display all pages and sub pages by level;//1: display only top-level pages;//2: display level 2 pages;//- 1: display all pages and sub pages by level;

Show_date=>,//Whether to display the creation date

Date_format=>get_option (date_format),//date format

Child_of=>0,//Specify the ID number of the parent page, and display the child pages under the parent page; 0 indicates that all sub pages are displayed;

Exclude=>,//which pages are excluded

Include=>,//which pages are included

Title_li=>Pages,//Whether to display the title of the page list, if not, set it to blank; Set the title as "Pages"

Echo=>1,//Whether to print it to the foreground page. 1 means display, 0 means not display, but only get the value.

Authors=>,//Specify the page created by a specific author

Link_before=>,//the content before the link<a>link_after=>,//the content after the link<a>

Exclude_tree=>,//Exclude parent/child trees

Sort_column=>menu_order,//sorting method, menu_order is set by background; Post_date by publishing time, post_modified by modifying time;

Sort_order=>DESC,//Sort order, ASC order, DESC is reverse order);

As you can see, there are many parameter values of the wp_list_pages() function. In the actual operation of WordPress theme template development, we generally use only a few of them.

Next, we will introduce how the wp_list_pages() function generates the navigation menu based on the page through an example. Let's first take a look at the single page created in the background of the wordpress website, as shown below:

From the above figure, we can see that there are six pages in the background of the wordpress website, of which "submission" is the parent page of "sub page 1" and "sub page 2".

Case 1: We add the following code to the header of the wordpress website template:

$menu=array (depth=>0, title_li=>Page navigation menu, echo=>1,); wp_list_pages($menu);

Let's go to the front page of the wordpress website to see the effect, as shown below:

We can see that the page navigation is displayed, and the sub pages are displayed hierarchically - indented by 2 spaces.

Case 2: Let's modify a parameter code, set the title to null, add a sorting parameter, and modify the hierarchical parameter value. The code is as follows:

$menu=array (depth=>1, title_li=>page navigation menu, echo=>1, sort_order=>DESC, sort_column=>menu_order,); wp_list_pages($menu);

At this time, let's take a look at the effect of the front page of the wordpress website, as shown below:

We can see that the title of the navigation menu has disappeared, and the hierarchy has disappeared, and the sorting has also changed. It is arranged according to the reverse order of page names. There are many parameters of wp_list_pages(), which are simple without one by one demonstration.

Case 3: The parameter of the wp_list_pages() function is of string type.

At the beginning, I said that the parameters of the wp_list_pages() function can be of two types, either string type or array type. We have used the array type in the first two cases. Here, we will introduce the string type again.

Here we take the code of the case to demonstrate how to change the parameters of array type into string type. The code is as follows:

wp_list_pages("depth=1&title=&echo=1&sort_order=DESC&sort_column=menu_order");

In the above code, we use a connector&this special symbol, which is used to connect multiple parameters. The symbol=in the middle need not be explained. It is the equal sign. Through this code, we also achieve the effect of Case 2.

If you want this page based navigation menu to be displayed horizontally at the top, you can modify the code and style of the CSS file of the wordpress website template. I won't say much here.

That's all for this lesson. Those are my views. If you have different views, please comment. At the same time, welcome [like, share, collect] and [follow] me.

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/1969.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

What are the main contents of wms system in warehouse management

Original title: What does the wms system mainly embody in warehouse management? What does the wms system mainly embody in warehouse management? Warehouse management has standardized and intelligent process oriented management. A good warehouse management mechanism can improve the efficiency of warehouse managers, relieve their pressure, and complete efficient and accurate work. 1. Warehouse management is accompanied by the progress of the times
1 year ago (2024-02-18)

How to implement the mptt comment function of CMS content management system in Django?, Django management page

During the daily development of content related Web systems in the directory, whether it is Blog or CMS, if you need to add links to interact with users, you must need the comment function. Next, you can implement the comment reply function in Django based on Python's MPTT framework. Note: Because the user comment function will involve a
three hundred and ninety-four
zero
1 year ago (2024-02-18)

Best CMS content management system in 2022, good novel in 2021

Looking for the best CMS software to build your website? At a high level, CMS or content management systems can help you create functional websites without having to use code to build every page from scratch. However, different CMS software has different advantages and disadvantages, so you need to choose the tool that best suits your specific needs and budget. To help, we accept
four hundred and six
zero
1 year ago (2024-02-18)

Shenzhen promotes the access of 5G base station energy storage system to the virtual power plant management center in the city. Does the Shenzhen 5g government subsidize the flow package charge

Xinhua News Agency, Shenzhen, December 14 (Reporter Wang Feng) At the 2022 Carbon Peak Carbon Neutralization Forum and Shenzhen International Low Carbon City Forum held here in Shenzhen, Shenzhen Virtual Power Plant Management Center signed a cooperation agreement on virtual power plant construction with China Tower, China Telecom, China Mobile, China Unicom, Huawei Digital Energy and other units on the 13th, which will jointly promote the city's 5G base station energy storage system
three hundred and forty-three
zero
1 year ago (2024-02-18)

Common website cms content management system recommendation, common website cms content management software

CMS is the abbreviation of "Content Management System", which means "Content Management System" in Chinese. These systems have developed common website functions and provided them to users for download, greatly improving the efficiency of website construction. The most common functions of CMS are column management, article management, product management, picture management
three hundred and twenty-eight
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: