【问题标题】:Wordpress wp_list_pages list siblings if no children?如果没有孩子,Wordpress wp_list_pages 列出兄弟姐妹?
【发布时间】:2019-01-15 20:48:39
【问题描述】:

努力尝试确定 wp_list_pages 正确的查询。

我基本上想放置一个侧边栏函数,根据内容的结构显示返回的 wp_list_pages 列表。如果用户所在的页面有孩子,我希望孩子显示在那里。

如果页面没有子页面,我希望在那里显示兄弟姐妹。

我知道这一定很简单,但我正在努力解决它。任何建议。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    从别人那里得到了一些帮助,效果很好!

    global $post;
    	if (is_page( )) {
    		$page = $post->ID;
    		$children=wp_list_pages( 'sort_column=menu_order&title_li=&echo=0&child_of=' . $page . '&depth=1' );
    		if ($children) {
    			$output = wp_list_pages ('sort_column=menu_order&title_li=' . $post->post_title . ' Subpages&echo=0&child_of=' . $page . '&depth=1');
    		}
    		else {
    			$page = $post->post_parent;
    			$output = wp_list_pages ('sort_column=menu_order&title_li=Similar Pages&echo=0&child_of=' . $page . '&depth=1');
    		}
    	}
    	return $output;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2019-05-06
      相关资源
      最近更新 更多