在Wordpress中列出孩子的兄弟页面

时间:2015-10-02 14:06:08

标签: php wordpress

我正在为酒店建立一个网站,在我的侧边栏文件中,我有一个PHP脚本来打印出子页面列表。结构如下:

  • 餐厅(早餐,午餐,晚餐)

  • 客房(标准间,双人间,豪华间)

因此,当用户在父页面(餐厅或客房)或子页面上时,基本上我想显示侧边栏中的子项(括号中的页面)页面。

但是,我的脚本似乎不起作用,并且不显示页面列表。

//SET UP FAMILY
    $children = get_pages('child_of='.$post->ID);
    $parent = $post->post_parent;
    $siblings = get_pages('child_of='.$parent);

    if(count($children) != 0 ) {
        $args = array(
            'depth' => 1,
            'title_li' => null,
            'sort_column' => 'menu_order',
            'child_of' => $post->ID
        );
    }

    else if($parent != 0) {
        $args = array(
            'depth' => 1,
            'title_li' => null,
            'sort_column' => 'menu_order',
            'exclude' => $post->ID,
            'child_of' => $parent
        );
    }

    if(count($siblings) > 1 && !is_null($args)) {
        echo "<ul class='pages'>";
        echo "<h2>Browse</h2>";
        wp_list_pages($args);
        echo "</ul>";
    }

我不介意菜单中是否显示当前页面。

0 个答案:

没有答案