<?php comments_template('', true); ?>不起作用

问题描述 投票:0回答:2

我想在我的single.php上添加评论。如果需要添加额外的代码或额外的文件,请通知我。提前致谢。这是我的 single.php 文件:

<div class="col-m-9">
    <?php if(have_posts()) : ?>
        <?php while(have_posts()) : the_post(); ?>
            <h3><a href="<?php the_permalink(); ?> ">
            <?php the_title(); ?></a></h3>
            <?php the_post_thumbnail('portfolio-thumb'); ?>
            <?php the_content(); ?>
            <?php comments_template('', true); ?>
        <?php endwhile; ?>
    <?php else : ?>
        <h2>404 not found:</h2>
    <?php endif; ?>
</div>

但它没有显示评论选项。我已经尝试了很长时间了。 我还没有添加comments.php

php wordpress
2个回答
0
投票

您的主题文件夹中需要有一个名为

comments.php
的文件才能渲染模板。 或者您可以指定文件名并将其作为函数的第一个参数传递。

https://developer.wordpress.org/reference/functions/comments_template/


0
投票

hey i have been looking for this answer 


function enable_comments_by_default($post_id, $post, $update) {
    // Only affect new posts
    if ($update || 'my_custom_post' !== $post->post_type) {
        return;
    }

    // Enable comments and pingbacks
    if (!isset($post->comment_status)) {
        wp_update_post(array(
            'ID' => $post_id,
            'comment_status' => 'open',
            'ping_status' => 'open',
        ));
    }
}`enter code here`
add_action('wp_insert_post', 'enable_comments_by_default', 10, 3);

© www.soinside.com 2019 - 2024. All rights reserved.