Php 如何在Wordpress中获取当前选定菜单项

Php 如何在Wordpress中获取当前选定菜单项,php,wordpress,Php,Wordpress,请告诉我如何获取//读取菜单中当前选定项的父项。。。。Wordpress//PHP 例如: 菜单结构: A -aa -ab -交流电 B -ba -bb -卑诗省 所以,如果用户选择,比如说“ba”项,那么我需要得到“B”项(…) 谢谢你你说的是面包屑。这将有助于: 本质上:$post->post\u parent将为您提供父页面的ID。如果您试图获取当前页面的父页面,您可以使用或您可以使用祖先谢谢大家的提示和指导 我用这种方式解决了这个问题: $current_page_id = $post-

请告诉我如何获取//读取菜单中当前选定项的父项。。。。Wordpress//PHP

例如:

菜单结构:

A -aa -ab -交流电

B -ba -bb -卑诗省

所以,如果用户选择,比如说“ba”项,那么我需要得到“B”项(…)


谢谢你

你说的是面包屑。这将有助于:


本质上:
$post->post\u parent
将为您提供父页面的ID。

如果您试图获取当前页面的父页面,您可以使用或您可以使用祖先

谢谢大家的提示和指导

我用这种方式解决了这个问题:

$current_page_id = $post->ID;
$page_children = fnGetPageChildren($current_page_id);

class currentpage_child {
    var $title;var $link;
        function set_data ($page_title,$page_link){
            $this->title = $page_title;
            $this->link = $page_link;
        }
}

function fnGetPageChildren ($page_id){
                    // Set up the objects needed
                    $my_wp_query = new WP_Query();
                    $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));

                    //get current page parrent id
                    $parent_id = wp_get_post_parent_id($page_id);
                    //get current page parent title
                    $parent_title = get_the_title($parent_id);

                    // Get the page as an Object
                    $obj_get_help =  get_page_by_title($parent_title);

                    // Filter through all pages and find Portfolio's children
                    $get_help_children = get_page_children( $obj_get_help->ID, $all_wp_pages);

                    $childrenpages_count = 0;
                        foreach ($get_help_children as $obj) {
                            $arr_currentpage_children[$childrenpages_count] = new currentpage_child();
                            $arr_currentpage_children[$childrenpages_count] -> set_data ($obj->post_title,$obj->guid);
                            $childrenpages_count++;
                        }

                    return $arr_currentpage_children;
            }

我不明白你想做什么,你能用图片解释一下吗?