动态Twitter关注按钮

问题描述

| 因此,我一直在测试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()
打印名称,后者返回名称。     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...