我们在做网站时很多时候有提供用户投稿的功能,那么用户投稿后需要审核,在后台如何提醒管理员有需要审核的文章呢?可以使用以下代码来实现:
function wp_my_admin_enqueue_scripts2( $hook ) {
global $wpdb;
$task_post = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'task' and (post_status='pending' or post_status='draft')");
if($task_post){
wp_enqueue_script( 'my_admin_script', get_stylesheet_directory_uri().'/static/js/admin.js',
false, null, true );
?>
<script>
var task_post_count = '<?php echo $task_post;?>';
</script>
<?php
}
}
add_action( 'admin_enqueue_scripts', 'wp_my_admin_enqueue_scripts2' );
admin.js代码
jQuery(function($){
$(".menu-top#menu-posts-task .wp-menu-name").append('<span class="update-plugins count-'+task_post_count+'"><span class="plugin-count">'+task_post_count+'</span></span>');
});
以上代码的以上就是在有待审核的任务时,在后台左侧菜单那个【任务】菜单上显示待审数量,红色圆圈标记。


0 个评论