从管理中筛选出子页面的最佳方式是什么?

时间:2012-04-27 作者:lkraav

我想用js总是可以隐藏它们的,但是有没有查询级子页面过滤器的代码片段?我只想保留顶级页面。

编辑:我的程序员想出了这个方法,请继续关注解决方案

1 个回复
SO网友:lkraav

这符合我们的需要:

# Parent filtering
function wps_restrict_manage_posts() {
    global $typenow;

    # only run this filter on page post type
    if ( $typenow == \'konverentsid\' ) {
        # Parent Page Filter (HTML)
        $args = array(
            \'post_type\' => \'konverentsid\',
            \'child_of\' => 0,
            \'show_option_none\' => __(\'Show all pages\'),
            \'depth\' => 1,
            \'name\' => \'wps_page_filter\',
            \'selected\' => $_GET[\'wps_page_filter\'],
        );
        $dropdown = wp_dropdown_pages( $args );
    }

}
add_action ( \'restrict_manage_posts\' , \'wps_restrict_manage_posts\' );

# Add an option to show top level pages only
add_filter ( \'wp_dropdown_pages\' , \'wps_insert_option_in_dropdown\' );
function wps_insert_option_in_dropdown ( $output ) {
    $filter = $_GET[\'wps_page_filter\'];
    if ( $filter == \'parent\' )
        $selected = \' selected="selected"\';
    else
        $selected = \'\';
    $second_option = __("Show all pages") . \'</option><option value="parent"\' . $selected . \'>\' . __("Parent Pages Only") . \'</option>\';
    return preg_replace( \'#Show all pages</option>#\' , $second_option , $output );
}
add_filter ( \'parse_query\', \'wps_admin_posts_filter\' );

function wps_admin_posts_filter( $query ) {
    global $pagenow;

    # Change query based on post_parent
    $wps_page_filter = $_GET[\'wps_page_filter\'];
    if ( is_admin() && $pagenow == \'edit.php\' && !empty( $wps_page_filter ) ) {
        if ( $wps_page_filter == \'parent\' )
            $query->query_vars[\'post_parent\'] = 0;
        else
            $query->query_vars[\'post_parent\'] = $wps_page_filter;
    }
}

结束