wordpress - How can I access {{comment.author.roles}}?
问题描述
I want to add a special style for admins who comment on a blog. I'm attempting to pull the roles for comment authors via {{ commment.author.roles }} per https://timber.github.io/docs/reference/timber-comment/#author, but it doesn't seem to return the proper roles, or even a normal \User object.
I came across this issue thread https://github.com/timber/timber/issues/1866 which seems to indicate this issue was fixed and merged, but it still doesn't seem to work for me.
I'm using WordPress v5.1.1 and Timber v1.9.4.
My single.php is pretty simple:
$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post
Timber::render( array( 'single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single.twig' ), $context );
Then in single.twig calling my comment.twig partial:
<ol class="comments__list" id="commentlist">
{% if post.comments %}
{% for cmt in post.comments %}
{% include "comment.twig" with {comment:cmt} %}
{% endfor %}
{% endif %}
</ol>
And in comment.twig attempting to use
{{comment.author.roles|join(', ')}}
returns NULL.
Also if I just dump the comment author ala
{{ dump(comment.author) }}
I get a seemingly truncated version of a \User object:
object(Timber\User)#1635 (12) { ["object_type"]=> string(4) "user" ["_link"]=> NULL ["avatar_override"]=> NULL ["description"]=> NULL ["display_name"]=> NULL ["first_name"]=> NULL ["last_name"]=> NULL ["id"]=> NULL ["user_nicename"]=> NULL ["roles":protected]=> NULL ["ID"]=> NULL ["name"]=> string(10) "Josh Masen" }
Any input on what I might be doing wrong here would be very much appreciated. I'm still pretty new to Timber so I decided to post here instead of creating an issue because I feel like I'm probably missing something.
解决方案
推荐阅读
- javascript - 使用 Hooks 和 onChange 处理程序进行反应以进行条件渲染
- google-bigquery - 更新_未_分区但_存在_流缓冲区的表中的行
- javascript - 我正在尝试做一个自定义翻译脚本。我制作了这个脚本,用字母替换符号。但有个问题
- github - 如何在 GITHUB 中使用没有远程分支的 Terraform 更新分支保护?
- laravel - Product_id 未传递给函数
- c++ - 当我按下任一 ALT 时,WINAPI 应用程序关闭,为什么?
- html - Django:模板表单操作未重定向
- python - Python:追加/扩展方法
- ios - 如何快速制作系统字体“黑色斜体”?
- javascript - Switch 语句返回未定义