【问题标题】:Wrapping Wordpress Comment Avatars包装 Wordpress 评论头像
【发布时间】:2013-09-13 15:18:25
【问题描述】:

我目前正在制作一个 Wordpress 主题,一切顺利。

它是响应式的,但我似乎对 cme​​ts 部分的头像有问题。我想要做的是将头像包装在一个单独的 div 中,以指定宽度并利用 img { max-width: 100%; } 。目前它在 DOM 中有兄弟姐妹,所以我不能在它的当前父级上执行此操作。有人会假设我需要在 functions.php 中使用自定义函数,然后在 wp_list_cmets 中使用回调参数?

当前输出:

    <div class="comment-author vcard">
       <img alt="" src="img_url" class="avatar avatar-74 photo">
       <cite class="fn">James</cite>
       <span class="says">says:</span>
</div>

谢谢。

【问题讨论】:

    标签: php wordpress comments avatar


    【解决方案1】:

    过滤器get_avatar 可以。注意这个函数也是pluggable,这意味着如果需要你可以用你自己的覆盖它。

    add_filter( 'get_avatar', 'b5f_get_avatar', 10, 5 );
    
    function b5f_get_avatar( $avatar, $id_or_email, $size, $default, $alt )
    {
        $avatar = '<div class="img-max-width">' . $avatar . '</div>';
        return $avatar;
    }
    

    以下是每个参数中接收到的值:

    /**
     * [avatar] => <img alt='' src='http://0.gravatar.com/avatar/ETCETERA/....' class='avatar avatar-64 photo' height='64' width='64' />
     * [id_or_email] => 1
     * [size] => 64
     * [default] => http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=64
     * [alt] => 
    */
    

    【讨论】:

    • 完美。谢谢。我实际上已经切换到我自己的自定义标记,但这回答了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 2020-05-26
    • 2018-10-12
    • 2013-08-20
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多