【问题标题】:Wordpress wp_list_pages: list parent page siblingsWordpress wp_list_pages:列出父页面兄弟
【发布时间】:2011-05-17 22:14:50
【问题描述】:

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

我的页面结构是这样的:

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

(当我在“CAR”页面上时,导航应该是 CAR、MOTORCYCLE、BICYCLE。当我在 MINIVAN 页面上时,导航应该是 CAR、MOTORCYCLE、BICYCLE。)

非常感谢您的帮助!

【问题讨论】:

  • 您是否制作了所有这些特定页面?还是他们的帖子?只是确保(我知道你说的是第 4 级页面)。所有主题都会出现这种情况吗?
  • 这些是页面。但我认为你误解了我的意思。我正在寻找可以执行上述操作的 wp_list_pages 语句。

标签: php wordpress navigation wordpress-theming


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

如果您不确定任何事情,请随时询问:)

【讨论】:

  • 伙计,这太完美了!我不得不稍微修改一下,所以第 4 和第 5 级显示第 4 级页面。非常感谢!
【解决方案2】:

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

$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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    相关资源
    最近更新 更多