【问题标题】:WordPress Custom Post Type Single Page (Comments)WordPress 自定义帖子类型单页(评论)
【发布时间】:2013-04-02 23:42:05
【问题描述】:

我创建了一个自定义帖子类型和一个可以正常工作的单页模板。但是我在为它启用单个页面上的 cmets 时遇到了问题。

这是我的功能:

    add_action('init', 'vblog'); 
    function vblog() {
    register_post_type('vblog', array(
    'labels' => array(
            'name' => __( 'VTV' ),
            'singular_name' => __( 'VTV' ),
            'add_new' => 'Add New VBlog',
            'add_new_item' => 'Add New VBlog',
            'edit' => 'Edit VBlog',
            'edit_item' => 'Edit VBlog',
            'new_item' => 'New VBlog',
            'view' => 'View VBlogs',
            'view_item' => 'View VBlog',
            'search_iteme' => 'Search VBlogs',
            'not_found' => 'No VBlogs Found',
            'not_found_in_trash' => 'No VBlogs found in Trash',
            'parent' => 'Parent VBlog',
    ),
    'public' => true,
    'supports'  =>  array('title', 'editor','custom-fields', 'thumbnail', 'revisions', 'comments'),
    'taxonomies' => array('category', 'post_tag')
));

}

所以我确保在支持数组中添加了“cmets”。请帮忙!!!

【问题讨论】:

  • 自定义帖子类型的单个模板是否添加了cmets。类似<?php comments_template( '', true ); ?>

标签: wordpress comments custom-post-type


【解决方案1】:

扩展评论作为答案。

您已正确注册 post_type 以支持 cmets。在您的 single-{post_type}.php 模板中,您需要在循环内调用 cmets 模板(在 endwhile 和 else endif 之间)。

if ( comments_open() || '0' != get_comments_number() )
        comments_template( '', true );

【讨论】:

    【解决方案2】:

    添加此代码single-vblog.php

    comments_template( '', true ); 
    

    如果显示评论关闭,您可以在 phpmyadmin 中运行此命令

    UPDATE wp_posts SET comment_status = 'open' WHERE post_type = 'vblog';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      相关资源
      最近更新 更多