当你修改一个评论的时候,是否会存在一种需求,就是在本页面里面看到关联文章的所有评论呢?
如果有这样的需求,那么本文值得你看看。
直接将下方的所有代码添加到function.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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
add_action( 'admin_menu', 'all_display_comments_add_meta_box' ); function all_display_comments_add_meta_box() { add_meta_box( 'commentsdiv', __( 'Comments' ), 'my_post_comment_meta_box', 'comment', 'normal', 'high' ); } function my_post_comment_meta_box( $comment ) { $post = get_post( $comment->comment_post_ID ); // manually define $post // Add the post ID input. echo '<input type="hidden" id="post_ID" value="' . $post->ID . '">'; // Then the AJAX nonce. wp_nonce_field( 'get-comments', 'add_comment_nonce', false ); $total = get_comments( array( 'post_id' => $post->ID, 'number' => 1, 'count' => true, ) ); $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' ); $wp_list_table->display( true ); if ( 1 > $total ) { echo '<p id="no-comments">' . __( 'No comments yet.' ) . '</p>'; } else { $hidden = get_hidden_meta_boxes( get_current_screen() ); if ( ! in_array( 'commentsdiv', $hidden, true ) ) { ?> <script type="text/javascript">jQuery(document).ready(function(){commentsBox.get(<?php echo $total; ?>, 10);});</script> <?php } ?> <p class="hide-if-no-js" id="show-comments"><a href="#commentstatusdiv" onclick="commentsBox.load(<?php echo $total; ?>);return false;"><?php _e( 'Show comments' ); ?></a> <span class="spinner"></span></p> <?php } wp_comment_trashnotice(); } add_action( 'admin_enqueue_scripts', 'my_admin_enqueue_scripts' ); function my_admin_enqueue_scripts() { // Enqueue the script only if the current page is comment.php if ( 'comment' === get_current_screen()->id ) { wp_enqueue_script( 'post' ); wp_enqueue_script( 'admin-comments' ); } } add_action( 'in_admin_header', 'my_in_admin_header' ); function my_in_admin_header() { if ( 'comment' === get_current_screen()->id ) { wp_comment_reply( '-1' ); } } |
安装上方代码之后效果如下:
感兴趣的朋友可以自己去尝试一下,直接复制黏贴就可以了,操作起来没有任何难度。