小工具      在线工具  汉语词典  dos游戏  css  js  c++  java

wordpress 父页面_如何在WordPress中显示父页面的子页面列表

java,python,php,wordpress,javascript,ViewUI 额外说明

收录于:17天前

WordPress 父页面

最近我们的一位用户问我们如何显示 WordPress 页面的子页面?通常,在处理包含子页面的网站时,您可能希望在侧边栏小部件或模板中的其他位置的父页面上显示这些子页面。在本文中,我们将向您展示如何在 WordPress 中显示父页面的子页面列表。

最近,我们的一位用户问我们如何显示WordPress页面的子页面?通常,在处理包含子页面的页面的网站时,您可能希望在侧边栏小部件或模板中的其他位置的父页面上显示这些子页面。在本文中,我们将向您展示如何在 WordPress 中显示父页面的子页面列表。

To see an example of a list of child pages on parent page, see the screenshot below that we have from OptinMonster’s 工作原理页面. You can also see this in use on WPBeginner’s 蓝图页.

要查看父页面上子页面列表的示例,请参见OptinMonster的“工作原理” 在页面中以下屏幕截图。 您还可以在WPBeginner的“ 蓝图页上看到此功能。

A parent page with a list of child pages

Before we get start, for those who are not familiar with Child Pages, please check out our guide on the 帖子和页面之间的区别 in WordPress. One of the important feature of pages is that they can be hierarchical. This means that a page can become a parent page and has child pages (i.e sub-pages) under it. This allows you to group different pages together under one parent page. For example, if you have a Product Page on a website, then you can add pages such as Features, Pricing, and Support as child pages. Each child page can have its own child pages as well.

在开始之前,对于那些不熟悉子页面的用户,请查看有关WordPress中帖子和页面的区别的指南。 页面的重要特征之一是它们可以是分层的。 这意味着页面可以成为父页面并在其下具有子页面(即子页面)。 这使您可以将一个父页面下的不同页面组合在一起。 例如,如果您在网站上有一个“产品页面”,则可以将诸如“功能”,“定价”和“支持”之类的页面添加为子页面。 每个子页面也可以有自己的子页面。

影片教学 Video Tutorial

演示地址

如果您不喜欢该视频或需要更多说明,请继续阅读。

如果您不喜欢该视频或需要更多说明,请继续阅读。

To create a child page, simply create or edit a page in WordPress like you would normally do. Under the 页面属性 meta box, choose a parent page from the drop down menu.

要创建子页面,只需像通常那样在WordPress中创建或编辑页面即可。 在页面属性元框下,从下拉菜单中选择一个父页面。

Creating a child page by assigning it a Parent page in WordPress

注意:如果您没有看到“页面属性”菜单,请单击屏幕右上角的“屏幕选项”按钮。它将显示一个菜单,您需要在其中确保选中页面属性。

注意:如果您没有看到“页面属性”菜单,请单击屏幕右上角的“屏幕选项”按钮。它将显示一个菜单,您需要在其中确保选择页面属性。

在WordPress的父页面上显示子页面 Displaying Child Pages on the Parent Page in WordPress

To list child pages under a parent page, you need to add the following code in a 特定于站点的插件, or in your theme’s 函数.php file:

要在父页面下列出子页面,您需要在具体的网站插件或主题的函数.php文件中添加以下代码:


function wpb_list_child_pages() { 

global $post; 

if ( is_page() && $post->post_parent )

	$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
	$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );

if ( $childpages ) {

	$string = '<ul>' . $childpages . '</ul>';
}

return $string;

}

add_shortcode('wpb_childpages', 'wpb_list_child_pages');

The code above first checks to see if a page has a parent or the page itself is a parent. If it is a parent page, then it displays the child pages associated with it. If it is a child page, then it displays all other child pages of its parent page. Lastly, if this is just a page with no child or parent page, then the code will simply do nothing. In the last line of the code, we have added a 短代码, so you can easily display child pages without modifying your page templates.

上面的代码首先检查页面是否具有父级,或者页面本身是父级。 如果它是父页面,则显示与其关联的子页面。 如果它是子页面,则显示其父页面的所有其他子页面。 最后,如果这只是一个没有子页面或父页面的页面,那么代码将什么都不做。 在代码的最后一行,我们添加了一个短代码 ,因此您可以轻松显示子页面而无需修改页面模板。

要显示子页面,只需在侧边栏中的页面或文本小部件中添加以下短代码:

要显示子页面,只需将以下短代码添加到侧边栏中的页面或文本小部件中:

[wpb_childpages]

[wpb_childpages]

In some cases, your theme may not be ready to execute shortcodes in a text widget. If it is not working, then see this tutorial on 如何在 WordPress 侧边栏小部件中使用短代码.

在某些情况下,您的主题可能尚未准备好在文本窗口小部件中执行短代码。 如果不起作用,请参阅本教程, 了解如何在 WordPress 侧边栏小部件中使用短代码

动态显示子页面而没有任何简码 Dynamically Display Child Pages Without Any Shortcode

使用短代码很方便,但使用短代码的问题是您必须在具有父页面或子页面的所有页面中添加短代码。您最终可能会在很多页面中使用短代码,有时您甚至可能忘记添加短代码。

使用短代码很方便,但使用短代码的问题是您必须在具有父页面或子页面的所有页面中添加短代码。您最终可能会在许多页面中使用短代码,有时您甚至可能忘记添加它们。

A better approach would be to edit the page template file in your theme, so that it can automatically display child pages. To do that you need to edit the main page.php template or 创建自定义页面模板 in your theme.

更好的方法是在主题中编辑页面模板文件,以便它可以自动显示子页面。 为此,您需要编辑page.php模板或在主题中创建自定义页面模板

在页面模板文件中,您需要在要显示子页面的位置添加这行代码。

在页面模板文件中,您需要在希望子页面出现的位置添加这行代码。


<?php wpb_list_child_pages(); ?>

就这样。您的主题现在将自动检测子页面并显示它们。

就这样。现在,您的主题将自动检测并显示子页面。

If you are using parent pages with lots of child pages that have their own child pages, then the WordPress admin view can get confusing. For a better way to organize parent and pages try using 管理栏视图.

如果您使用的父页面具有很多子页面,而这些子页面具有自己的子页面,则WordPress管理员视图可能会造成混淆。 为了更好地组织父级和页面,请尝试使用管理列视图

我们希望本文能帮助您列出 WordPress 中的子页面。如果您有任何问题或反馈,请在下面发表评论,让我们知道。

我们希望本文能帮助您列出 WordPress 中的子页面。如果您有任何问题或反馈,请在下面发表评论并告诉我们。

Source: 托马斯·格里芬

资料来源: 托马斯·格里芬

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-display-a-list-of-child-pages-for-a-parent-page-in-wordpress/

WordPress 父页面

. . .

相关推荐

额外说明

进入主页时如何默认到内存控制台

例如用户退出后,下次登陆系统,能默认打开之前工作路径。 可以在index.html,index-topnav.html,去掉window.performance.navigation.type == 1  将 if($.common.equals("hi

额外说明

如何用Python实现多张图片的拼接

本文实例讲述了Python实现拼接多张图片的方法。分享给大家供大家参考。具体分析如下: 这里所述计划实现如下操作: ① 用Latex写原始博文,生成PDF文档; ② 将PDF转成高清的PNG格式的图片; ③ 将多个PNG格式的图片合并成一大张图片; ④

额外说明

atoi的使用及实现

文章目录 一,atoi的使用 实例 二、atoi的实现 一,atoi的使用 作用: int atoi(const char *str) 把参数 str 所指向的字符串转换为一个整数(类型为 int 型)。 返回值:该函数返回转换后的长整数,如果没有执行有

额外说明

运维知识点-MySQL从小白到入土

MySQL从小白到入土 mysql 服务器安装 windows mysql 服务 漏洞复现-mysql jdbc反序列化-权限绕过 mysql 服务器安装 https://dev.mysql.com/downloads/mysql/ https://

额外说明

python——reportlab

QQ 1274510382 Wechat JNZ_aming 商业联盟 QQ群538250800 技术搞事 QQ群599020441 解决方案 QQ群152889761 加入我们 QQ群649347320 共享学习 QQ群674240731 纪年科技am

额外说明

2.搭建Fabric区块链网络环境——前提条件和fabric的安装

(1)安装前提条件: 这些前提条件的满足确保了你可以顺利地搭建和运行 Fabric 区块链网络,并进行链码的开发、部署和执行。 安装 Docker:确保系统上已经安装了 Docker,并且 Docker 服务正在运行。 Docker:Fabric 使用

额外说明

算法面试题:数组中重复的数字

题目: 在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。 数组中某些数字是重复的,但不知道有几个数字重复了. 也不知道每个数字重复了几次。请找出数组中任意一个重复的数字. public static int findRepea

额外说明

【Go 基础篇】Go语言结构体详解:打开自定义类型的大门

嗨,Go语言学习者们!在编程的世界里,数据是核心,而结构体(Struct)是一种能够帮助我们更有组织地存储和操作数据的重要工具。在本篇博客中,我们将深入探讨Go语言中结构体的概念、定义、初始化、嵌套、方法以及与面向对象编程的关系,带你逐步领略结构体的魅力

额外说明

为什么 MySQL 选择 Repeatable Read 作为默认隔离级别

为什么 MySQL 选择 Repeatable Read 作为默认隔离级别? 我们知道,ANSI/ISO SQL-92 标准定义了 4 种隔离级别,从低到高依次为: 读未提交(Read Uncommitted)、读已提交(Read Committed)、

额外说明

【云原生 • Docker】镜像的迁移与备份、Dockerflie 使用方法

目录 一、迁移与备份 1. 容器保存为镜像 2. 镜像备份 3. 镜像恢复与迁移 二、Dockerflie 1. 认识 Dockerfile 2. Dockerfile 常用命令 3. 使用 Dockerfile 构建镜像 一、迁移与备份 迁移和备份主要

ads via 小工具