私はここ数時間、この問題に取り組んできました。なぜオンラインでどこにヘルプがあるのか見つからないのです。
Wordpress - have_comments()が機能しないのはなぜですか?
ほとんどの場合、私は最初からカスタムテーマを作っています。 WordPressは常にデフォルトの「Hello world!」で始まります。投稿とその投稿に関連付けられているデフォルトコメントが表示されます。
"Hello world!"投稿はfalseに評価すべきではありませんが、何らかの理由で評価されるべきではありません ご覧のとおり、WordPressが "comments.php"という名前のファイルからコードを実行できるようにするcomments_templates関数を使用しようとしましたが、問題にエラーの要素を追加し、そのコードをコメントに追加しました。 php "は決してアクセスされないので、今のところ私はそれを残しています。
<?php
if(have_posts()) : while(have_posts()) : the_post();
get_template_part('content', get_post_format());
// comments_template('/comments.php', true);
if(have_comments()) :
echo 'OMG COMMENTS WORK';
foreach (get_comments() as $comment) :
echo $comment -> comment_content;
echo $comment -> comment_author;
echo apply_filters('comment_text', $comment -> comment_content);
endforeach;
else :
echo 'There are no comments to display here (this statement may or may not be true...)';
endif;
endwhile; endif;
?>