在 WordPress 的父页面内显示子页面列表作为菜单 [英] Display a list of child pages as a menu, inside a parent page in WordPress

查看:26
本文介绍了在 WordPress 的父页面内显示子页面列表作为菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 WordPress 网站,我需要在父页面中创建一个由子页面组成的菜单.所以,我通过两种方式正确地实现了这一点:

I'm building a WordPress site and I need to create a menu made of child pages inside a parent page. So, I've achieved this correctly in 2 ways:

我想要得到的与本网站左侧的相似:http://optinmonster.com/how-it-works/actionable-insights/

What I'm trying to get is smth similar as in the left side of this site: http://optinmonster.com/how-it-works/actionable-insights/

但是我遇到了一个问题,因为当我点击我创建的菜单元素时,它们会作为自己的页面打开.虽然我希望它们显示在父页面上...这个想法是我希望根据我单击的菜单项在父页面中显示不同的内容.我该怎么办??有这个插件吗??

But I'm having a problem, cause when I click on the menu elements I created, they open up as pages of their own. While I want them to show up on the parent page... The idea is that I want different content to display in the parent page based on the menu items I click on. What should I do?? Is there a plugin for this??

PS,我相信我还没有找到解决这个问题的方法,因为我在谷歌上搜索错了,所以我遇到的问题有明确的名称吗??

P.S, I believe that I haven't yet found a solution for this problem because I'm googling it wrong, so is there a definite name for the problem I'm having??

我非常感谢您的帮助.

推荐答案

<?php
    if ($post->post_parent) {
        $page = $post->post_parent;
    } else {
        $page = $post->ID;
    }

    $children = wp_list_pages(array(
        'child_of' => $page,
        'echo' => '0',
        'title_li' => ''
    ));

    if ($children) {
        echo "<ul>\n".$children."</ul>\n";
    } 
?>

这篇关于在 WordPress 的父页面内显示子页面列表作为菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆