Allow queries by post type. Enable paging in Manage->Pages

git-svn-id: http://svn.automattic.com/wordpress/trunk@3564 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-02-21 08:39:58 +00:00
parent 29540c8e2b
commit b4166c403b
4 changed files with 66 additions and 87 deletions

View File

@ -643,19 +643,24 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) {
}
}
function page_rows($parent = 0, $level = 0, $pages = 0) {
function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) {
global $wpdb, $class, $post;
if (!$pages)
$pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' ORDER BY menu_order");
if ($pages) {
foreach ($pages as $post) {
start_wp();
if ($post->post_parent == $parent) {
$post->post_title = wp_specialchars($post->post_title);
$pad = str_repeat('— ', $level);
$id = $post->ID;
$class = ('alternate' == $class) ? '' : 'alternate';
if (! $pages)
return false;
foreach ($pages as $post) {
setup_postdata($post);
if ( $hierarchy && ($post->post_parent != $parent) )
continue;
$post->post_title = wp_specialchars($post->post_title);
$pad = str_repeat('— ', $level);
$id = $post->ID;
$class = ('alternate' == $class) ? '' : 'alternate';
?>
<tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
<th scope="row"><?php echo $post->ID; ?></th>
@ -670,12 +675,7 @@ function page_rows($parent = 0, $level = 0, $pages = 0) {
</tr>
<?php
page_rows($id, $level +1, $pages);
}
}
} else {
return false;
if ( $hierarchy) page_rows($id, $level + 1, $pages);
}
}

View File

@ -19,13 +19,12 @@ require_once('admin-header.php');
</form>
<?php
wp('post_type=page&orderby=menu_order&what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1');
$show_post_type = 'page';
if ( isset($_GET['s']) )
wp();
if ( $_GET['s'] )
$all = false;
else
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page'");
$all = true;
if ($posts) {
?>
@ -40,30 +39,17 @@ if ($posts) {
<th scope="col"></th>
</tr>
<?php
if ( isset($_GET['s']) ) {
foreach ( $posts as $post ) :
$class = ('alternate' != $class) ? 'alternate' : ''; ?>
<tr id='page-<?php echo $post->ID; ?>' class='<?php echo $class; ?>'>
<th scope="row"><?php echo $post->ID; ?></th>
<td>
<?php echo $pad; ?><?php the_title() ?>
</td>
<td><?php the_author() ?></td>
<td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>
<td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td>
<td><?php if ( current_user_can('edit_page', $post->ID) ) { echo "<a href='page.php?action=edit&amp;post=$post->ID' class='edit'>" . __('Edit') . "</a>"; } ?></td>
<td><?php if ( current_user_can('delete_page', $post->ID) ) { echo "<a href='page.php?action=delete&amp;post=$post->ID' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the &quot;%s&quot; page.\\n&quot;OK&quot; to delete, &quot;Cancel&quot; to stop."), wp_specialchars(get_the_title('','',0), 1)) . "' );\">" . __('Delete') . "</a>"; } ?></td>
</tr>
<?php
endforeach;
} else {
page_rows();
}
page_rows(0, 0, $posts, $all);
?>
</table>
<div id="ajax-response"></div>
<div class="navigation">
<div class="alignleft"><?php next_posts_link(__('&laquo; Previous Entries')) ?></div>
<div class="alignright"><?php previous_posts_link(__('Next Entries &raquo;')) ?></div>
</div>
<?php
} else {
?>

View File

@ -55,11 +55,8 @@ if ($drafts || $other_drafts) {
<div class="wrap">
<h2>
<?php
$what_to_show = 'posts';
$posts_per_page = 15;
$posts_per_archive_page = -1;
wp();
wp('what_to_show=posts&posts_per_page=15&posts_per_archive_page=-1');
if ( is_month() ) {
single_month_title(' ');

View File

@ -114,14 +114,6 @@ class WP_Query {
$this->is_single = false;
} elseif (!empty($qv['s'])) {
$this->is_search = true;
switch ($qv['show_post_type']) {
case 'page' :
$this->is_page = true;
break;
case 'attachment' :
$this->is_attachment = true;
break;
}
} else {
// Look for archive queries. Dates, categories, authors.
@ -205,10 +197,6 @@ class WP_Query {
if ( ($this->is_date || $this->is_author || $this->is_category)) {
$this->is_archive = true;
}
if ( 'attachment' == $qv['show_post_type'] ) {
$this->is_attachment = true;
}
}
if ('' != $qv['feed']) {
@ -280,6 +268,9 @@ class WP_Query {
$distinct = '';
$join = '';
if ( !isset($q['post_type']) )
$q['post_type'] = 'post';
$post_type = $q['post_type'];
if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
$q['posts_per_page'] = get_settings('posts_per_page');
if ( !isset($q['what_to_show']) )
@ -550,25 +541,26 @@ class WP_Query {
// Order by
if (empty($q['orderby'])) {
$q['orderby']='date '.$q['order'];
$q['orderby'] = 'post_date '.$q['order'];
} else {
// Used to filter values
$allowed_keys = array('author', 'date', 'category', 'title', 'modified');
$allowed_keys = array('author', 'date', 'category', 'title', 'modified', 'menu_order');
$q['orderby'] = urldecode($q['orderby']);
$q['orderby'] = addslashes_gpc($q['orderby']);
$orderby_array = explode(' ',$q['orderby']);
if (!in_array($orderby_array[0],$allowed_keys)) {
$orderby_array[0] = 'date';
}
$q['orderby'] = $orderby_array[0].' '.$q['order'];
if (count($orderby_array)>1) {
for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) {
// Only allow certain values for safety
if (in_array($orderby_array[$i],$allowed_keys)) {
$q['orderby'] .= ',post_'.$orderby_array[$i].' '.$q['order'];
}
}
if ( empty($orderby_array) )
$orderby_array[] = $q['orderby'];
$q['orderby'] = '';
for ($i = 0; $i < count($orderby_array); $i++) {
// Only allow certain values for safety
$orderby = $orderby_array[$i];
if ( 'menu_order' != $orderby )
$orderby = 'post_' . $orderby;
if ( in_array($orderby_array[$i], $allowed_keys) )
$q['orderby'] .= (($i == 0) ? '' : ',') . "$orderby {$q['order']}";
}
if ( empty($q['orderby']) )
$q['orderby'] = 'post_date '.$q['order'];
}
//$now = gmdate('Y-m-d H:i:59');
@ -587,10 +579,10 @@ class WP_Query {
} elseif ($this->is_single) {
$where .= ' AND (post_type = "post")';
} else {
$where .= ' AND (post_type = "post" AND (post_status = "publish"';
$where .= " AND (post_type = '$post_type' AND (post_status = 'publish'";
if ( $pagenow == 'post.php' || $pagenow == 'edit.php' )
$where .= " OR post_status = 'future'";
if ( is_admin() )
$where .= " OR post_status = 'future' OR post_status = 'draft'";
else
$distinct = 'DISTINCT';
@ -636,8 +628,7 @@ class WP_Query {
$groupby = " $wpdb->posts.ID ";
$groupby = apply_filters('posts_groupby', $groupby);
$join = apply_filters('posts_join_paged', $join);
$orderby = "post_" . $q['orderby'];
$orderby = apply_filters('posts_orderby', $orderby);
$orderby = apply_filters('posts_orderby', $q['orderby']);
$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";
$this->request = apply_filters('posts_request', $request);
@ -1448,7 +1439,8 @@ class WP_Rewrite {
class WP {
var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview');
var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'show_post_type');
var $private_query_vars = array('posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');
var $extra_query_vars = array();
var $query_vars;
var $query_string;
@ -1463,9 +1455,7 @@ class WP {
$this->query_vars = array();
if (! empty($extra_query_vars))
parse_str($extra_query_vars, $extra_query_vars);
else
$extra_query_vars = array();
parse_str($extra_query_vars, $this->extra_query_vars);
// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
@ -1539,7 +1529,7 @@ class WP {
$this->matched_query = $query;
// Parse the query.
parse_str($query, $query_vars);
parse_str($query, $perma_query_vars);
// If we're processing a 404 request, clear the error var
// since we found something.
@ -1561,8 +1551,8 @@ class WP {
if (isset($error))
unset($error);
if ( isset($query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') )
unset($query_vars);
if ( isset($perma_query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') )
unset($perma_query_vars);
$this->did_permalink = false;
}
@ -1572,20 +1562,26 @@ class WP {
for ($i=0; $i<count($this->public_query_vars); $i += 1) {
$wpvar = $this->public_query_vars[$i];
if (isset($extra_query_vars[$wpvar]))
$this->query_vars[$wpvar] = $extra_query_vars[$wpvar];
if (isset($this->extra_query_vars[$wpvar]))
$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
elseif (isset($GLOBALS[$wpvar]))
$this->query_vars[$wpvar] = $GLOBALS[$wpvar];
elseif (!empty($_POST[$wpvar]))
$this->query_vars[$wpvar] = $_POST[$wpvar];
elseif (!empty($_GET[$wpvar]))
$this->query_vars[$wpvar] = $_GET[$wpvar];
elseif (!empty($query_vars[$wpvar]))
$this->query_vars[$wpvar] = $query_vars[$wpvar];
elseif (!empty($perma_query_vars[$wpvar]))
$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
else
$this->query_vars[$wpvar] = '';
}
for ($i=0; $i<count($this->private_query_vars); $i += 1) {
$wpvar = $this->private_query_vars[$i];
if (isset($this->extra_query_vars[$wpvar]))
$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
}
if ( isset($error) )
$this->query_vars['error'] = $error;
}
@ -1632,15 +1628,15 @@ class WP {
function build_query_string() {
$this->query_string = '';
foreach ($this->public_query_vars as $wpvar) {
if (isset($this->query_vars[$wpvar]) && '' != $this->query_vars[$wpvar]) {
foreach (array_keys($this->query_vars) as $wpvar) {
if ( '' != $this->query_vars[$wpvar] ) {
$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
}
}
foreach ($this->private_query_vars as $wpvar) {
if (isset($GLOBALS[$wpvar]) && '' != $GLOBALS[$wpvar]) {
if (isset($GLOBALS[$wpvar]) && '' != $GLOBALS[$wpvar] && ! isset($this->extra_query_vars[$wpvar]) ) {
$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
$this->query_string .= $wpvar . '=' . rawurlencode($GLOBALS[$wpvar]);
}