Display a list of child pages as a menu, inside a

2019-06-01 08:20发布

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:

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

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

I would really appreciate some help.

标签: wordpress
1条回答
三岁会撩人
2楼-- · 2019-06-01 09:04
<?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";
    } 
?>
查看更多
登录 后发表回答