【问题标题】:Comment Author Link on Wordpress在 Wordpress 上评论作者链接
【发布时间】:2023-03-13 00:42:01
【问题描述】:

在 wordpress 表单中,当您以访客身份发表评论时,会有一个网站字段来填写您的网址。如果我们填写那个框,我们可以通过调用这个函数来获取链接

<?php echo get_comment_author_link(); ?>

但是,如果您已登录并且没有在您的个人资料中添加该网站,则当您发表评论时。您的用户名上没有链接。

我想要的是,如果登录用户没有网站,会有一个链接将他们带到他们的个人资料页面,类似于http://www.example.com?author=21

有什么我可以使用的功能吗?请帮帮我。谢谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    把它放到你主题的functions.php中;

    function force_comment_author_url($comment)
    {
        // does the comment have a valid author URL?
        $no_url = !$comment->comment_author_url || $comment->comment_author_url == 'http://';
    
        if ($comment->user_id && $no_url) {
            // comment was written by a registered user but with no author URL
            $comment->comment_author_url = 'http://www.example.com/?author=' . $comment->user_id;
        }
        return $comment;
    }
    add_filter('get_comment', 'force_comment_author_url');
    

    【讨论】:

    • 感谢就像一个魅力。我真的很想给你投票。目前我没有足够的代表投票。再次感谢您。
    【解决方案2】:

    我想一个解决方法是让一个 php/mySQL 脚本将 wordpress 数据库中的空数据库字段更新为您想要的值

    【讨论】:

      猜你喜欢
      • 2017-09-08
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 2012-01-19
      • 1970-01-01
      • 2017-05-23
      相关资源
      最近更新 更多