WordPress 仪表盘显示待审核的文章列表

对于多用户投稿的WordPress站点,免不了要对用户提交的文章进行审核,但是每次都要点击进入文章列表查看是否有文章待审,是不是很麻烦?其实,我们可以在WordPress仪表盘直接显示待审的文章列表,登录以后一眼就可以看到了。

pending-posts-dashboard-widget-wpdaxue_com

要做到这个,只需要将下面的代码添加到当前主题的 functions.php 文件即可:

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
/**
 * WordPress 仪表盘显示待审核的文章列表
 * http://blog.wpjam.com/m/pending-posts-dashboard-widget/
 */
add_action('wp_dashboard_setup', 'wpjam_modify_dashboard_widgets' );
function wpjam_modify_dashboard_widgets() {
	global $wp_meta_boxes;
 
	if(current_user_can('manage_options')){ //只有管理员才能看到
		add_meta_box( 'pending_posts_dashboard_widget', '待审文章', 'pending_posts_dashboard_widget_function','dashboard', 'normal', 'core' );
	}
}
 
function pending_posts_dashboard_widget_function() {
	global $wpdb;
	$pending_posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts}  WHERE post_status = 'pending' ORDER BY post_modified DESC");
 
	if($pending_posts){ //判断是否有待审文章		echo '<ul>';
		foreach ($pending_posts as $pending_post){
			echo '<li><a href="'.admin_url().'post.php?post='.$pending_post->ID.'&action=edit">'.$pending_post->post_title.'</a></li>';
		}
		echo '</ul>';
	}else echo '目前没有待审文章';}

/**
* WordPress 仪表盘显示待审核的文章列表
* http://blog.wpjam.com/m/pending-posts-dashboard-widget/
*/
add_action(‘wp_dashboard_setup’, ‘wpjam_modify_dashboard_widgets’ );
function wpjam_modify_dashboard_widgets() {
global $wp_meta_boxes; if(current_user_can(‘manage_options’)){ //只有管理员才能看到
add_meta_box( ‘pending_posts_dashboard_widget’, ‘待审文章’, ‘pending_posts_dashboard_widget_function’,’dashboard’, ‘normal’, ‘core’ );
}
} function pending_posts_dashboard_widget_function() {
global $wpdb;
$pending_posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_status = ‘pending’ ORDER BY post_modified DESC"); if($pending_posts){ //判断是否有待审文章
echo ‘<ul>’;
foreach ($pending_posts as $pending_post){
echo ‘<li><a href="’.admin_url().’post.php?post=’.$pending_post->ID.’&action=edit">’.$pending_post->post_title.'</a></li>’;
}
echo ‘</ul>’;
}else echo ‘目前没有待审文章’;
}

代码来自:我爱水煮鱼 http://blog.wpjam.com/m/pending-posts-dashboard-widget/,在源代码添加了一个判断是否有待审文章,如果没有,显示提示文字。

本人擅长Ai、Fw、Fl、Br、Ae、Pr、Id、Ps等软件的安装与卸载,精通CSS、JavaScript、PHP、ASP、C、C++、C#、Java、Ruby、Perl、Lisp、Python、Objective-C、ActionScript、Pascal等单词的拼写,熟悉Windows、Linux、OS X、Android、iOS、WP8等系统的开关机。

通过下面的方式来联系我们:

电邮:138762189@qq.com

联系QQ:点击这里给我发消息

官方站:www.tadke.com

※ ※ 联系请加我的企鹅号 ※※

※ ※技术支持请微信联系站长 ※※

Copyright © 2023 Tadke.com. 琼ICP备20000547号