1

好吧,这真的让我很烦!我写了一个函数(嗯,修改了一个与 wordpress 代码非常相似的函数),只要页面有子页面或是子页面,它就会列出所有子页面和父页面。那一点效果很好,但我现在想做的是让它在一个自定义字段(添加到导航)中查找,该字段具有到另一个页面的路径以添加到列表的末尾。它检查该自定义字段的页面和父级。

它似乎在呼应所有正确的细节,但由于某种原因不会将该页面添加到列表中。非常感谢任何帮助!

function add_sec_nav_w_extras(){

    global $post;
    global $wpdb;
    $key = 'add-to-nav';
    $addition = get_post_meta($post->ID, $key, TRUE);
    if($addition == '') {$addition = get_post_meta($post->post_parent, $key, TRUE);}
    if($addition != '') {
        $addition_page = get_page_by_path($addition);
    }
        echo("Addition page: ".$addition_page->post_title."<br/>Addition ID: ".$addition_page->ID."<br/>Current: ".$post->ID."<br/>Parent: ".$post->post_parent);

    ?><section id="secondnav_w_parent" class="fix"><ul><?php
    if($post->post_parent != "0") { // If post has parent, list that parent and all its children
        wp_list_pages( array('title_li'=>'','include'=>$post->post_parent) );
        wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->post_parent) );
        if($addition_page != ''){
            wp_list_pages( array('title_li'=>'','include'=>$addition_page->ID) );
        }
    }

    else if(get_pages('child_of='.$post->ID)) { // If post is a parent, list itself and all children
        wp_list_pages( array('title_li'=>'','include'=>$post->ID) );
        wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->ID) );
        if($addition_page != ''){
            wp_list_pages( array('title_li'=>'','include'=>$addition_page->ID) );
        }
    }
    ?></ul></section><?php
}

编辑:

好的,现在我知道为什么它没有出现了……我告诉它不要出现!我正在使用排除页面插件,以便页面不会出现在主导航中,这显然会影响使用 wp_list_pages 的任何内容。所以现在我需要找到一种方法来强制它在那里......有什么想法吗?

编辑2:

现在禁用排除页面插件并使用主导航的自定义菜单。有点痛,但我想还不错。如果有人有更好的建议,请告诉我!

4

0 回答 0