代码之家  ›  专栏  ›  技术社区  ›  Gowri

如何隐藏WordPress页面中的注释

  •  0
  • Gowri  · 技术社区  · 15 年前

    我已经在一个页面中关闭了评论,但页面中仍显示以下行。如何禁用这些行。有人请帮帮我!

    由Sankar于2010年10月12日发布 注释关闭编辑 注释已关闭。

    6 回复  |  直到 8 年前
        1
  •  3
  •   Peter Rowell    15 年前

    您使用的是什么版本的wp?

    在wp 3+中(可能更早),您只需转到仪表板,单击页面,单击相关页面的编辑,向下滚动到标记为讨论的部分,然后取消选择允许评论和允许引用和回指框。然后把附在页面上的任何评论都扔掉。

    如果你的意思是 而不是 那么保罗是正确的,他认为有必要对主题做一个小的编辑。注意:尽可能使用 儿童主题 所以你不会无意中破坏主题。

    假设您使用的是wp 3和默认的210主题,请编辑wp content/themes/twenty ten/comments.php(或创建子主题,复制comments.php,然后继续)。

    comments.php,第70行,内容如下:

    if ( ! comments_open() ) :
    

    将其更改为:

    if ( 0 && ! comments_open() ) :
    

    这会有效地终止后面的行,即输出“注释已关闭”的行,但不需要完全删除它。显然,如果您使用的是不同的主题,那么您必须自己在comments.php中查找相应的行。

    请注意,这是一个快速和肮脏的黑客,将影响所有帖子。如果你只想为选定的文章做这些,你就必须做一些更复杂的事情。

        2
  •  3
  •   Mudassar ali    11 年前

    将此代码添加到function.php文件中

    // Disable support for comments and trackbacks in post types
     function df_disable_comments_post_types_support() {
    $post_types = get_post_types();
    foreach ($post_types as $post_type) {
        if (post_type_supports($post_type, 'comments')) {
            remove_post_type_support($post_type, 'comments');
            remove_post_type_support($post_type, 'trackbacks');
        }
    }
    }
    
     add_action('admin_init', 'df_disable_comments_post_types_support');
    
      // Close comments on the front-end
     function df_disable_comments_status() {
    return false;
    }
    
    add_filter('comments_open', 'df_disable_comments_status', 20, 2);
    add_filter('pings_open', 'df_disable_comments_status', 20, 2);
    
    // Hide existing comments
    function df_disable_comments_hide_existing_comments($comments) {
    $comments = array();
    return $comments;
    }
    
     add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2);
    
     // Remove comments page in menu
     function df_disable_comments_admin_menu() {
    remove_menu_page('edit-comments.php');
    }
    
       add_action('admin_menu', 'df_disable_comments_admin_menu');
    
     // Redirect any user trying to access comments page
      function df_disable_comments_admin_menu_redirect() {
     global $pagenow;
    if ($pagenow === 'edit-comments.php') {
        wp_redirect(admin_url());
        exit;
    }
     }
    
      add_action('admin_init', 'df_disable_comments_admin_menu_redirect');
    
      // Remove comments metabox from dashboard
       function df_disable_comments_dashboard() {
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
    }
    
      add_action('admin_init', 'df_disable_comments_dashboard');
    
      // Remove comments links from admin bar
     function df_disable_comments_admin_bar() {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
     }
    
     add_action('init', 'df_disable_comments_admin_bar');
    
        3
  •  1
  •   Vineesh C    11 年前

    转到WordPress页面-单击“快速编辑”,您将看到为评论提供勾号的选项,您可以避免该勾号。

    yourdomainname.com/wp admin/edit.php?后类型

    然后

    单击每个页面的快速编辑。

        4
  •  0
  •   Paul McMillan    15 年前

    您需要编辑显示在模板外的行。

        5
  •  0
  •   Moxet Jan    12 年前

    最简单的方法是在theme/page.php中找到以下行并删除或注释它。

    <?php comments_template( '', true ); ?>
    
        6
  •  0
  •   HDJEMAI    8 年前

    您可以编辑页面模板。腌制 get_template_part('comments') 并移除它