wp_list_pages没有列出包含的页面

时间:2012-04-12 21:44:27

标签: php wordpress custom-fields

好的,这真让我烦恼!我编写了一个函数(好吧,修改了一个非常类似于wordpress codex的函数),它列出了所有子页面和父页面,只要页面有子项或者是子项。这一点工作正常,但我现在要做的是让它看起来在自定义字段(add-to-nav)中,该字段具有另一个页面的路径以添加到列表的末尾。它会检查该自定义字段的页面和父级。

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

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的任何内容。所以现在我需要找到一种方法强制它在那里......有什么想法吗?

EDIT2:

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

0 个答案:

没有答案