Wordpress:只显示导航级别的方法?

时间:2012-06-19 06:10:11

标签: wordpress

在wordpress中有没有办法在第三级时显示第四个导航级别?

谢谢!

2 个答案:

答案 0 :(得分:0)

试试这个:

<?php
  if($post->post_parent) {
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  $titlenamer = get_the_title($post->post_parent);
  }

  else {
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
  $titlenamer = get_the_title($post->ID);
  }
  if ($children) { ?>

  <h2> <?php echo $titlenamer; ?> </h2>
  <ul>
  <?php echo $children; ?>
  </ul>

<?php } ?>

此代码将显示当前页面的所有子页面。所以当你在3级时,如果存在,它将显示4级子页面。

Refer this Codex section

答案 1 :(得分:0)

您可以尝试此功能:

function getPages($pid=0) {
    global $wpdb;
    $pages = $wpdb->get_results($sql = "
        SELECT *
        FROM $wpdb->posts
        WHERE
            post_type = 'page' &&
            post_status = 'publish' &&
            post_parent = $pid
        ORDER BY menu_order
    ");
    return $pages;
}

$ pid是您的案例中的第三个导航级别页面ID的父ID。