从特定帖子获取评论

时间:2019-11-29 作者:Old Nick

我正试图从一个特定的帖子中获取评论,并将其显示在网站的其他地方。这是我用来获取current 邮递我如何编辑它,以便它从id引用的另一篇文章中获取评论?

<?php
if (have_comments()) {
    ?>
    <h3 class="comments-title">
        <?php
        echo \'\';
        ?>
    </h3> 
    <ol class="comments-list">
        <?php
        wp_list_comments(
            array(
                \'style\' => \'ol\',
                \'format\' => \'html5\',
                \'avatar_size\' => \'100\'
            )
        );
        ?>
    </ol>
    <div class="comments-navigation">
        <div class=\'previous-comments-link\'><?php previous_comments_link(); ?></div>
        <div class=\'next-comments-link\'><?php next_comments_link(); ?></div>
    </div>
    <?php
}
?>

1 个回复
SO网友:Sam

这将允许您通过id提取帖子的评论,然后编辑帖子返回的内容信息。您需要添加CSS和html来设置注释的样式。

    $args = array(
    \'author_email\' => \'\',
    \'author__in\' => \'\',
    \'author__not_in\' => \'\',
    \'include_unapproved\' => \'\',
    \'fields\' => \'\',
    \'ID\' => \'\',
    \'comment__in\' => \'\',
    \'comment__not_in\' => \'\',
    \'karma\' => \'\',
    \'number\' => \'\',
    \'offset\' => \'\',
    \'orderby\' => \'\',
    \'order\' => \'DESC\',
    \'parent\' => \'\',
    \'post_author__in\' => \'\',
    \'post_author__not_in\' => \'\',
    //Post id here
    \'post_id\' => \'162\',
    ////////////////////////
    \'post__in\' => \'\',
    \'post__not_in\' => \'\',
    \'post_author\' => \'\',
    \'post_name\' => \'\',
    \'post_parent\' => \'\',
    \'post_status\' => \'\',
    \'post_type\' => \'\',
    \'status\' => \'all\',
    \'type\' => \'\',
    \'type__in\' => \'\',
    \'type__not_in\' => \'\',
    \'user_id\' => \'\',
    \'search\' => \'\',
    \'count\' => false,
    \'meta_key\' => \'\',
    \'meta_value\' => \'\',
    \'meta_query\' => \'\',
    \'date_query\' => null, // See WP_Date_Query
);

$comments = get_comments($args);
foreach($comments as $comment) :
     // echos the comment author and the content, you can use any of the above tags to create the displayed data but will need to custom the html/CSS style
    echo($comment->comment_author . \'<br />\' . $comment->comment_content. \'<br />\');
endforeach;


        ?>
    <div class="comments-navigation">
        <div class=\'previous-comments-link\'><?php previous_comments_link(); ?></div>
        <div class=\'next-comments-link\'><?php next_comments_link(); ?></div>
    </div>
    <?php

相关推荐

如何将Single-*.php放在特定的文件夹中?

我正在组织和清理代码,以使其更易于维护。事实证明,我的网站有很多自定义帖子类型,所以我有大约15个单发-***。我的网站根目录下的php文件。为了使树视图更清晰,我希望所有这些文件都列在一个特定的“单个”文件夹中。显然,Wordpress只识别单个-***。位于主题根目录的php文件。有办法解决这个问题吗?提前感谢您的帮助。