Changeset 6808
- Timestamp:
- 02/13/2008 09:30:26 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/edit-pages.php
r6804 r6808 46 46 47 47 $status_links = array(); 48 $num_posts = wp_count_posts('page'); 48 49 foreach ( $post_stati as $status => $label ) { 49 50 $class = ''; … … 51 52 if ( !in_array($status, $avail_post_stati) ) 52 53 continue; 53 54 $num_posts = wp_count_posts('page', $status); 54 55 55 if ( $status == $_GET['post_status'] ) 56 56 $class = ' class="current"'; 57 57 58 58 $status_links[] = "<li><a href=\"edit-pages.php?post_status=$status\"$class>" . 59 sprintf($label[2], $num_posts ) . '</a>';59 sprintf($label[2], $num_posts->$status) . '</a>'; 60 60 } 61 61 $class = empty($_GET['post_status']) ? ' class="current"' : ''; -
trunk/wp-admin/edit.php
r6807 r6808 53 53 <?php 54 54 $status_links = array(); 55 $num_posts = wp_count_posts('post'); 55 56 foreach ( $post_stati as $status => $label ) { 56 57 $class = ''; … … 59 60 continue; 60 61 61 $num_posts = wp_count_posts('post', $status);62 62 if ( $status == $_GET['post_status'] ) 63 63 $class = ' class="current"'; 64 64 65 65 $status_links[] = "<li><a href=\"edit.php?post_status=$status\"$class>" . 66 sprintf($label[2], $num_posts ) . '</a>';66 sprintf($label[2], $num_posts->$status) . '</a>'; 67 67 } 68 68 $class = empty($_GET['post_status']) ? ' class="current"' : ''; -
trunk/wp-admin/index.php
r6766 r6808 38 38 39 39 <?php 40 $num_posts = wp_count_posts('post', 'publish'); 41 42 $num_pages = wp_count_posts('page', 'publish'); 43 44 $num_drafts = wp_count_posts('post', 'draft'); 45 46 $num_future = wp_count_posts('post', 'future'); 47 48 $num_comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); 40 $num_posts = wp_count_posts( 'post' ); 41 $num_pages = wp_count_posts( 'page' ); 49 42 50 43 $num_cats = wp_count_terms('category'); … … 54 47 $post_type_texts = array(); 55 48 56 if ( $num_posts) {57 $post_type_texts[] = '<a href="edit.php">'.sprintf( __ngettext( '%s post', '%s posts', $num_posts ), number_format_i18n( $num_posts) ).'</a>';49 if ( !empty($num_posts->publish) ) { 50 $post_type_texts[] = '<a href="edit.php">'.sprintf( __ngettext( '%s post', '%s posts', $num_posts->publish ), number_format_i18n( $num_posts->publish ) ).'</a>'; 58 51 } 59 if ( $num_pages) {60 $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( __ngettext( '%s page', '%s pages', $num_pages ), number_format_i18n( $num_pages) ).'</a>';52 if ( !empty($num_pages->publish) ) { 53 $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( __ngettext( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>'; 61 54 } 62 if ( $num_drafts) {63 $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( __ngettext( '%s draft', '%s drafts', $num_ drafts ), number_format_i18n( $num_drafts) ).'</a>';55 if ( !empty($num_posts->draft) ) { 56 $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( __ngettext( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>'; 64 57 } 65 if ( $num_future) {66 $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_ future ), number_format_i18n( $num_future ) ).'</a>';58 if ( !empty($num_posts->future) ) { 59 $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( __ngettext( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>'; 67 60 } 68 61 -
trunk/wp-includes/post.php
r6803 r6808 783 783 784 784 /** 785 * wp_count_posts() - Count number of posts with a given type and status785 * wp_count_posts() - Count number of posts with a given type 786 786 * 787 787 * {@internal Missing Long Description}} … … 792 792 * 793 793 * @param string $type Post type 794 * @param string $status Post status 795 * @return int Number of posts 796 */ 797 function wp_count_posts( $type = 'post', $status = 'publish' ) { 794 * @return array Number of posts for each status 795 */ 796 function wp_count_posts( $type = 'post' ) { 798 797 global $wpdb; 799 798 800 return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s", $type, $status) ); 799 $count = $wpdb->get_results( $wpdb->prepare( "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s GROUP BY post_status", $type ), ARRAY_A ); 800 801 $stats = array( ); 802 foreach( (array) $count as $row_num => $row ) { 803 $stats[$row['post_status']] = $row['num_posts']; 804 } 805 806 return (object) $stats; 801 807 } 802 808
Note: See TracChangeset
for help on using the changeset viewer.