问题描述
|
因此,我一直在测试Twitter的新“关注”按钮,并且在浏览ZDNet.com时,我注意到在他们的作者简历中,每个作者都有一个“关注”按钮。有趣的是,该按钮将根据作者的身份进行更改。这是一个示例:http://www.zdnet.com/blog/btl/sony-predicts-32-billion-loss-following-psn-hacking-japan-earthquake。
我尝试在我的博客LonePlacebo.com上复制相同的想法,并取得了一定的成功。
下面的代码是我使用某些PHP的作者简介。我使用了一些if语句来检查作者,并且确实产生了我希望的动态按钮。但是,它还会以纯文本形式两次输出作者的姓名。
<?PHP if ( arras_get_option(\'display_author\') ) : ?>
<div class=\"about-author clearfix\">
<?PHP echo get_avatar(get_the_author_Meta(\'ID\'),48); ?>
<h4>Written by: <?PHP the_author(); ?></h4>
<?PHP the_author_Meta(\'description\'); ?>
<!--check if author is Tony -->
<?PHP if (the_author() == \"Tony Hue\") : ?>
<a href=\"http://twitter.com/tonykhue\" class=\"twitter-follow-button\">Follow @tonykhue</a>
<script src=\"http://platform.twitter.com/widgets.js\" type=\"text/javascript\"></script>
<?PHP endif; ?>
<!--check if author is Joseph-->
<?PHP if (the_author() == \"Joseph Chang\") : ?>
<a href=\"http://twitter.com/ballinacup\" class=\"twitter-follow-button\">Follow @ballinacup</a>
<script src=\"http://platform.twitter.com/widgets.js\" type=\"text/javascript\"></script>
<?PHP endif; ?>
</div>
<?PHP endif; ?>
任何帮助,将不胜感激。谢谢!
更新我尝试更新代码,以便将来有更多作者使用。在下面更新的代码中对get_author_Meta()的调用返回了Twitter字段中作者个人资料中提供的信息。我希望代码在作者未提供任何Twitter信息的情况下将默认的“关注”按钮显示给@loneplacebo,但如果这样做,则显示一个链接到其Twitter帐户的按钮。
但问题是,如果未提供Twitter帐户,则代码确实会按预期返回默认按钮。任何想法如何解决这个问题?
<?PHP if ( the_author_Meta(\'twitter\',$current_author->ID) ) : ?>
<!--if no Twitter info provided -->
<a href=\"http://twitter.com/loneplacebo\" class=\"twitter-follow-button\">Follow @loneplacebo</a>
<script src=\"http://platform.twitter.com/widgets.js\" type=\"text/javascript\"></script>
<?PHP else : ?>
<!--else,link to author\'s twitter account-->
<a href=\"<?PHP the_author_Meta(\'twitter\',$current_author->ID); ?>\" class=\"twitter-follow-button\">Follow @tonykhue</a>
<script src=\"http://platform.twitter.com/widgets.js\" type=\"text/javascript\"></script>
<?PHP endif; ?>
解决方法
代替
the_author()
,使用get_the_author()
。 the_author()
打印名称,后者返回名称。