默认情况下,页面上的“讨论”复选框未选中?

时间:2012-04-05 作者:onetrickpony

Possible Duplicate:
setting comments off as default for pages and custom post types?

创建新页面时,我希望这两个复选框(来自“讨论”元框)在默认情况下显示为未选中状态。

这可以通过编程实现吗?

"Discussion" meta box

4 个回复
最合适的回答,由SO网友:developdaly 整理而成

您可以重新注册“页面”帖子类型并省去评论功能。

add_action( \'init\', \'my_new_page_type\' );

function my_new_page_type() {
    register_post_type( \'page\', array(
        \'labels\' => array(
            \'name_admin_bar\' => _x( \'Page\', \'add new on admin bar\' ),
        ),
        \'public\' => true,
        \'publicly_queryable\' => false,
        \'_builtin\' => true, /* internal use only. don\'t use this when registering your own post type. */
        \'_edit_link\' => \'post.php?post=%d\', /* internal use only. don\'t use this when registering your own post type. */
        \'capability_type\' => \'page\',
        \'map_meta_cap\' => true,
        \'hierarchical\' => true,
        \'rewrite\' => false,
        \'query_var\' => false,
        \'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'page-attributes\', \'custom-fields\', \'revisions\' ),
    ) );
}
实际答案:original source here
function default_comments_off( $data ) {
    if( $data[\'post_type\'] == \'page\' && $data[\'post_status\'] == \'auto-draft\' ) {
        $data[\'comment_status\'] = 0;
        $data[\'ping_status\'] = 0;
    }

    return $data;
}
add_filter( \'wp_insert_post_data\', \'default_comments_off\' );

SO网友:chrisguitarguy

重新注册page 帖子类型有点过多。remove_post_type_support 更简单一点。结合answer 由@developdaly提及,您将有效地关闭评论。

<?php
add_action( \'init\', \'wpse48145_remove_comments\', 99 );
/**
 * Removes support for comments from Pages.
 * 
 * @uses remove_post_type_support
 */
function wpse48145_remove_comments()
{
    remove_post_type_support( \'page\', \'comments\' );
}

SO网友:Dankicity

这让我烦了一段时间,所以我做了一些挖掘:

function wpse48145_unchecked_page_discussion () {
      if( \'page\' == $_REQUEST[ \'post_type\' ]  ) {
        add_filter( \'pre_option_default_comment_status\', \'wpse48145_unchecked_page_discussion_filter\' );
        // & if you want...
        add_filter( \'pre_option_default_ping_status\', \'wpse48145_unchecked_page_discussion_filter\' );
    }
}
add_action( \'load-post-new.php\', \'wpse48145_unchecked_page_discussion\' );

function wpse48145_unchecked_page_discussion_filter ( $val ) {
    return \'closed\';
}
自WP 3.4.2起的工程

SO网友:Chip Bennett

转到Dashboard -> Settings -> DiscussionDefault Article settings

  • 取消选中“允许来自其他博客的链接通知(pingback和trackback)”和“允许人们对新文章发表评论”
    1. 这些更改不会更改现有帖子的设置。如果要更改现有帖子,请执行Bulk EditDashboard -> Posts 屏幕

      抱歉,我一开始误解了你的问题。WordPress不提供基于帖子类型设置默认评论状态的UI。

      注:this is a known issue.

    结束

    相关推荐

    Metabox image upload value

    我正在使用本教程中WP tuts的元框http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-3-extra-fields/ 一切正常,但我不知道如何调用图像上传程序的值。在我的索引中。php我使用了此代码<?php $image_upload = get_post_meta($post->ID, $field[\'custom_image\'], true);?> <?php print_r($im