1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

add_action('wp_dashboard_setup', 'custom_dashboard_widgets');

function custom_dashboard_widgets() {
	global $wp_meta_boxes;
	wp_add_dashboard_widget('top_10_posts', 'Top 10 Posts', 'top_10_posts_widget');
}

function top_10_posts_widget() {
	global $post;
	$loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 10, 'meta_key' => 'Views', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) );
	
	echo "<p style=\"margin-left:20px\"><strong>Title<span style=\"float:right\">Views</span></strong></p>\n";
	echo "<ol>\n";
	
	while ( $loop->have_posts() ) : $loop->the_post();
		$meta_views = get_post_meta($post->ID,'Views',true);
		echo "<li><a href=\"" . get_permalink() . "\">" . get_the_title() . "</a><span style=\"float:right\">" . $meta_views . "</span></li>\n";
	endwhile;
	
	echo "<ol>\n";
}

?>