0

当我在第三级时,wordpress 有没有办法只显示第四个导航级别?

谢谢!

4

2 回答 2

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 级子页面。

请参阅此 Codex 部分

于 2012-06-19T09:07:12.517 回答
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。

于 2012-06-19T11:17:42.203 回答