WordPress 仪表盘显示待审核的文章列表
对于多用户投稿的WordPress站点,免不了要对用户提交的文章进行审核,但是每次都要点击进入文章列表查看是否有文章待审,是不是很麻烦?其实,我们可以在WordPress仪表盘直接显示待审的文章列表,登录以后一眼就可以看到了。
要做到这个,只需要将下面的代码添加到当前主题的 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 '目前没有待审文章';} |
代码来自:我爱水煮鱼 http://blog.wpjam.com/m/pending-posts-dashboard-widget/,倡萌在源代码添加了一个判断是否有待审文章,如果没有,显示提示文字。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
1 条评论
发表评论
要发表评论,您必须先登录。
如何让投稿者 发的文章,保存为草稿,需要审核通过,投稿者在后台发的文章