WordPress 中的自定义帖子类型和评论

发布于 2024-12-07 07:59:48 字数 64 浏览 0 评论 0原文

WordPress 是否可以在自定义帖子类型上显示评论和评论表单,以及如何做到这一点?

提前致谢。

Is it possible in wordpress to display comments and comment form on custom post type, and how to do that?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦回梦里 2024-12-14 07:59:48

将此属性“注释”放在以下行中非常重要:

'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail', 'revisions', 'author', 'page-attributes' ),

在您的functions.php文件中

// register post type MySpecialPost
add_action( 'init', 'register_cpt_MySpecialPost' );
function register_cpt_MySpecialPost() {
    $labels = array( 
        'name' => _x( 'MySpecialPost', 'MySpecialPost' ),
        'singular_name' => _x( 'MySpecialPost', 'MySpecialPost' ),
        'add_new' => _x( 'Ajouter', 'MySpecialPost' ),
        'add_new_item' => _x( 'Ajouter une MySpecialPost', 'MySpecialPost' ),
        'edit_item' => _x( 'Modifier', 'MySpecialPost' ),
        'new_item' => _x( 'Nouvelle MySpecialPost', 'MySpecialPost' ),
        'view_item' => _x( 'Voir la MySpecialPost', 'MySpecialPost' ),
        'search_items' => _x( 'Recherche', 'MySpecialPost' ),
        'not_found' => _x( 'Aucune MySpecialPost trouvé', 'MySpecialPost' ),
        'not_found_in_trash' => _x( 'Aucune MySpecialPost trouvé', 'MySpecialPost' ),
        'parent_item_colon' => _x( 'Parent Service:', 'MySpecialPost' ),
        'menu_name' => _x( 'MySpecialPost', 'MySpecialPost' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => false,
        'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail', 'revisions', 'author', 'page-attributes' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 21,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'page'
    );
    register_post_type( 'MySpecialPost', $args );
}

It is very important that you put this attributes "comments" in this line :

'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail', 'revisions', 'author', 'page-attributes' ),

in your functions.php file

// register post type MySpecialPost
add_action( 'init', 'register_cpt_MySpecialPost' );
function register_cpt_MySpecialPost() {
    $labels = array( 
        'name' => _x( 'MySpecialPost', 'MySpecialPost' ),
        'singular_name' => _x( 'MySpecialPost', 'MySpecialPost' ),
        'add_new' => _x( 'Ajouter', 'MySpecialPost' ),
        'add_new_item' => _x( 'Ajouter une MySpecialPost', 'MySpecialPost' ),
        'edit_item' => _x( 'Modifier', 'MySpecialPost' ),
        'new_item' => _x( 'Nouvelle MySpecialPost', 'MySpecialPost' ),
        'view_item' => _x( 'Voir la MySpecialPost', 'MySpecialPost' ),
        'search_items' => _x( 'Recherche', 'MySpecialPost' ),
        'not_found' => _x( 'Aucune MySpecialPost trouvé', 'MySpecialPost' ),
        'not_found_in_trash' => _x( 'Aucune MySpecialPost trouvé', 'MySpecialPost' ),
        'parent_item_colon' => _x( 'Parent Service:', 'MySpecialPost' ),
        'menu_name' => _x( 'MySpecialPost', 'MySpecialPost' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => false,
        'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail', 'revisions', 'author', 'page-attributes' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 21,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'page'
    );
    register_post_type( 'MySpecialPost', $args );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文