dougehe2022 2014-10-28 21:41
浏览 67

评论者应该只看到他在wordpress中的评论

I'm building a site for a research and my participants will be all logged in to use the site. I would like to make these participants able to see only their own comments, so other users' comments will be hidden.

I'm using the comments.php file with, among other things, this simple code:

<?php if ( have_comments() ) : ?>

      <ol class="commentlist">
          <?php wp_list_comments(); ?>
      </ol>

      <?php if ( ! comments_open() ) : ?>
          <p class="no-comments">Comments are closed</p>
      <?php endif; ?>

<?php endif; ?>

What do I need to place around this code to filter the comments and show them only to their owners? Thanks.

  • 写回答

1条回答 默认 最新

  • duanliexi1052 2014-10-28 21:55
    关注

    You need to edit the comments template and use a combination of this

    get_comment(get_comment_ID())->user_id;
    

    which returns the user id of whoever commented, and compare it to the current user with

    get_current_user_id();
    

    Both return 0 if the commenter wasn't registered or if the current user isn't logged in, respectively.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀