jpmcc_fold_page_menus_widget.php0000644000175000017500000001174410770724113016124 0ustar johnjohnID)) { $x = $post->ID; $inclusions = "(post_parent <> " . strval($x) . ")"; do { $include = $wpdb->get_results("SELECT post_parent " . "FROM $wpdb->posts " . "WHERE ID = " . $x . " " . "LIMIT 1",ARRAY_N); $x = $include[0][0]; $inclusions .= " AND (post_parent <> " . $x . ")"; } while ($x <> 0); /* The exclude list consist of all the pages whose IDs are *not* on the include list */ $rows = $wpdb->get_results("SELECT ID " . "FROM $wpdb->posts WHERE (post_type = 'page') AND " . $inclusions, ARRAY_N); if ( count($rows) ) { foreach ( $rows as $row ) { foreach ( $row as $ro ) { if ($exclusions <> "") $exclusions .= ","; $exclusions .= strval($ro); } } } } if ($exclusions <> "") $exclusions = "exclude=" . $exclusions . "&"; return $exclusions; } function jpmcc_fold_pages_widget( $args ) { extract( $args ); $options = get_option( 'jpmcc_fold_pages_widget' ); $title = empty( $options['title'] ) ? __( 'Pages' ) : $options['title']; $sortby = empty( $options['sortby'] ) ? 'menu_order' : $options['sortby']; /* There appears to be a bug in wp_list_pages in WP 2.3.3 where it's ignoring the first item in the list? so we'll give it a dummy */ $exclude = jpmcc_fold_page_menus('123456789'); if ( $sortby == 'menu_order' ) { $sortby = 'menu_order, post_title'; } $out = wp_list_pages( array('title_li' => '', 'sort_column' => $sortby, 'exclude' => $exclude, 'echo' => 0 ) ); if ( !empty( $out ) ) { ?>