| | 61 | $query_str = apply_filters('manage_pages_query', $query_str); |
| | 62 | wp($query_str); |
| | 63 | } else { |
| | 64 | $paged = isset($_GET['paged']) ? intval($_GET['paged']) : 1; |
| | 65 | $paged_size = 30; |
| | 66 | |
| | 67 | $where = "post_type = 'page'"; |
| | 68 | if (isset($_GET['s'])) { |
| | 69 | $where .= " AND post_title LIKE '%" . $wpdb->escape($_GET['s']) . "%'"; |
| | 70 | $paged = 0; |
| | 71 | } |
| | 72 | if (isset($_GET['post_status'])) { |
| | 73 | $where .= " AND post_status = '" . $wpdb->escape($_GET['post_status']) . "'"; |
| | 74 | if ($_GET['post_status'] != 'publish') $paged = 0; |
| | 75 | } |
| | 76 | if (isset($_GET['author'])) { |
| | 77 | $where .= " AND post_author = " . $wpdb->escape($_GET['author']); |
| | 78 | $paged = 0; |
| | 79 | } |
| | 80 | |
| | 81 | $total_pages = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE $where"); |
| | 82 | |
| | 83 | $sql = "SELECT ID, post_parent, post_date, post_date_gmt, post_modified, post_modified_gmt, post_author, '' AS post_content, post_name, post_status, post_title, post_type FROM $wpdb->posts WHERE $where ORDER BY menu_order, post_title"; |
| | 84 | |
| | 85 | $all_pages = $wpdb->get_results($sql); |
| | 86 | |
| | 87 | if ($paged) { |
| | 88 | $all_pages_by_id = array(); |
| | 89 | $page_children = array(); |
| | 90 | |
| | 91 | foreach ($all_pages as $page) { |
| | 92 | $all_pages_by_id[$page->ID] = $page; |
| | 93 | $page_children[$page->post_parent][] = $page; |
| | 94 | } |
| | 95 | |
| | 96 | function build_page_tree($parent_id) { |
| | 97 | global $page_children; |
| | 98 | $tree = array(); |
| | 99 | if (isset($page_children[$parent_id])) { |
| | 100 | foreach ($page_children[$parent_id] as $child) { |
| | 101 | $child->children = build_page_tree($child->ID); |
| | 102 | $tree[] = $child; |
| | 103 | } |
| | 104 | } |
| | 105 | return $tree; |
| | 106 | } |
| | 107 | |
| | 108 | function build_page_array($tree) { |
| | 109 | $array = array(); |
| | 110 | foreach ($tree as $page) { |
| | 111 | $array[] = $page; |
| | 112 | $array = array_merge($array, build_page_array($page->children)); |
| | 113 | } |
| | 114 | return $array; |
| | 115 | } |
| | 116 | |
| | 117 | $page_tree = build_page_tree(0); |
| | 118 | $page_array = build_page_array($page_tree); |
| | 119 | $posts = array_slice($page_array, ($paged - 1) * $paged_size, $paged_size); |
| | 120 | |
| | 121 | if ($posts) { |
| | 122 | while ($posts[0]->post_parent) { |
| | 123 | $parent = $all_pages_by_id[$posts[0]->post_parent]; |
| | 124 | $parent->post_title .= ' (continued)'; |
| | 125 | $posts = array_merge(array($parent), $posts); |
| | 126 | } |
| | 127 | } |
| | 128 | } else { |
| | 129 | $posts = $all_pages; |
| | 130 | } |
| | 131 | } |
| | 132 | |