给你,这是我很快做出来的东西,看起来效果很好:
<?php
/*
Plugin Name: admin-filter-by-week
Plugin URI: http://en.bainternet.info
Description: answer to Filtering posts on Post Administration Page by Week Number instead of by Month
http://wordpress.stackexchange.com/questions/19186/filtering-posts-on-post-administration-page-by-week-number-instead-of-by-month
Version: 1.0
Author: Bainternet
Author URI: http://en.bainternet.info
*/
add_filter( \'parse_query\', \'week_admin_posts_filter\' );
add_action( \'restrict_manage_posts\', \'ba_admin_posts_filter_restrict_manage_posts\' );
function week_admin_posts_filter( $query )
{
global $pagenow;
if ( is_admin() && $pagenow==\'edit.php\' && isset($_GET[\'weekly_archive-dropdown\']) && $_GET[\'weekly_archive-dropdown\'] != \'\') {
$link = $_GET[\'weekly_archive-dropdown\'];
//http://en.bainternet.info/?m=2011&w=22
$pos = strpos($link, \'?m=\');
if ($pos !== false) {
$m = substr($link, $pos + 3);
$wpos = strpos($m, \'&w=\');
$w = substr($m, $wpos + 3);
$m = substr($m, 0, $wpos + 3);
$query->query_vars[\'year\'] = $m;
$query->query_vars[\'w\'] = $w;
$query->query_vars[\'post_status\'] = array(\'publish\',\'pending\',\'draft\',\'future\',\'private\');
}
}
}
function hack_weekly_archives($w){
$types = "IN(\'publish\',\'pending\',\'draft\',\'future\',\'private\')";
$w = str_replace("= \'publish\'",$types,$w);
return $w;
}
function ba_admin_posts_filter_restrict_manage_posts()
{
add_filter(\'getarchives_where\',\'hack_weekly_archives\');
?>
<select name="weekly_archive-dropdown">
<option value=""><?php echo esc_attr( __( \'Select Week\' ) ); ?></option>
<?php wp_get_archives( \'type=weekly&format=option&show_post_count=1\' ); ?>
</select>
<?php
remove_filter(\'getarchives_where\',\'hack_weekly_archives\');
}