WordPress wp_list_pages:列出父页面兄弟姐妹

发布于 2024-10-05 08:45:53 字数 452 浏览 0 评论 0原文

我现在正在努力让它工作一段时间。我很接近,但找不到可行的解决方案。

我的页面结构是这样的:

1 FIRST LEVEL
  2 SECOND LEVEL
    3 THIRD LEVEL
      4 CAR
         5 SUV
         5 MINIVAN
         5 FULLSIZE
      4 MOTORCYCLE
      4 BICYCLE
  2 SECOND LEVEL
  2 SECOND LEVEL
1 FIRST LEVEL

我需要一个 wp_list_pages 语句来执行以下操作:在第 4 级和第 5 级页面上(并且仅在这些页面上),导航列出所有第 4 级页面。

(当我在“汽车”页面上时,导航应该是汽车,摩托车,自行车。而且当我在迷你货车页面上时,导航应该是汽车,摩托车,自行车。)

非常感谢您的帮助!

I'm trying to get this working for quite a while now. I get close but can't find a working solution.

My page structure is like this:

1 FIRST LEVEL
  2 SECOND LEVEL
    3 THIRD LEVEL
      4 CAR
         5 SUV
         5 MINIVAN
         5 FULLSIZE
      4 MOTORCYCLE
      4 BICYCLE
  2 SECOND LEVEL
  2 SECOND LEVEL
1 FIRST LEVEL

I need a wp_list_pages statement that does the following: on 4th and 5th level pages (and ONLY on those) the navigation lists all 4th level pages.

(When i'm on page "CAR" the navigation should be CAR,MOTORCYCLE,BICYCLE. And also when i'm on page MINIVAN the navigation should be CAR,MOTORCYCLE,BICYCLE.)

Thank you very much for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

$ancestors = get_post_ancestors($post);
if (count($ancestors) >= 3) {
    $parent = $ancestors[2]; // third level page ID
    wp_list_pages('depth=1&child_of=' . $parent);
}

如果您有任何不确定的地方,请随时询问:)

$ancestors = get_post_ancestors($post);
if (count($ancestors) >= 3) {
    $parent = $ancestors[2]; // third level page ID
    wp_list_pages('depth=1&child_of=' . $parent);
}

Feel free to ask if you're unsure of anything :)

墨落画卷 2024-10-12 08:45:54

这是我最终使用的代码,感谢 TheDeadMedic 的回答。 (我取消了一页级别,所以它是第三和第四级别)

$ancestors = get_post_ancestors($post);
if (count($ancestors) == 2) {
   $parent = $ancestors[0];
}
elseif (count($ancestors) == 3) {
   $parent = $ancestors[1];
}

if ($parent) { 
   $tabs = wp_list_pages('depth=1&child_of=' . $parent);
}

Here's the code i finally used, thanks to TheDeadMedic's answer. (I canceled one page level so it's for 3rd and 4th level)

$ancestors = get_post_ancestors($post);
if (count($ancestors) == 2) {
   $parent = $ancestors[0];
}
elseif (count($ancestors) == 3) {
   $parent = $ancestors[1];
}

if ($parent) { 
   $tabs = wp_list_pages('depth=1&child_of=' . $parent);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文