【问题标题】:Comments not showing in custom post type - Wordpress自定义帖子类型中未显示评论 - Wordpress
【发布时间】:2011-09-29 22:43:36
【问题描述】:

我创建了一个自定义帖子类型,我想显示并允许 cmets。

我在 function.php 中有这个:

// Add Custom Post Types
    add_action( 'init', 'thm_post_types' );

// Add Custom Post Types Function
    require_once ( THEME_INCLUDES . 'theme-post-types.php' );

    require_once ( THEME_INCLUDES . 'theme-comments.php' );

在我的 theme-post-types.php 我有:

register_post_type( 'product',
    array(
        'labels' => array(
            'name' => 'Product Items',
            'singular_name' => 'Product' ,
            'add_new' => 'Add New Product',
            'add_new_item' => 'Add New Product Item' ,
            'edit' => 'Edit Product',
            'edit_item' => 'Edit Product Item',
        ),
        'description' => 'Product Items.' ,
        'public' => true,
        'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ), // ***** i believe this is the problem ******
        'taxonomies' => array('category', 'post_tag')

    )
);
register_taxonomy( 'product_category', array( 'product' ), array( 'label' => "Categories", "singular_label" => "Category" ) );

最后在我的 theme-cmets.php 中:

function thm_format_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
    <div class="comment" id="comment-<?php comment_ID() ?>">
        <div class="avatar"><?php echo get_avatar( $comment, $size='80' ); ?>
        <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ) ?>
        </div>
        <div class="comment-text">
            <cite><?php comment_author_link(); ?></cite>
            <small><?php comment_date( 'F d, Y - G:i ' ); ?></small>
            <div class="separator-line" style="margin-bottom:10px; margin-top:5px;"></div>
            <?php if ($comment->comment_approved == '0') : ?>
                <p><em><?php _e( 'Your comment is awaiting moderation.' ); ?></em></p>
            <?php endif; ?>
            <?php comment_text() ?>
        </div>
        <div class="clear"></div>
    </div>
    </li>

在我的自定义帖子类型中我有:

<div id="tabs-3">
            <?php comments_template(); ?>
</div>

自定义帖子显示内容,但未显示 cmets 或评论表单...有什么想法吗?

【问题讨论】:

    标签: posts comments


    【解决方案1】:

    您是否尝试通过 add_post_type_support() 为您的自定义帖子类型添加评论支持?

    例如

    <?php
    add_post_type_support( 'product', array( 'comments' ) );
    ?>
    

    【讨论】:

      【解决方案2】:

      在此之后,您需要在后台的屏幕选项中启用“讨论”和“评论”。完成此操作后,您可以为每个自定义帖子类型启用/禁用 cmets。

      【讨论】:

        【解决方案3】:

        如果你这样使用它会起作用的。

        'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'comments' )
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-11-29
          • 1970-01-01
          • 2015-05-24
          • 1970-01-01
          • 1970-01-01
          • 2016-12-29
          • 1970-01-01
          相关资源
          最近更新 更多