dongtuwu8548 2011-06-04 04:49
浏览 121
已采纳

动态Twitter关注按钮

So, I've been testing out Twitter's new Follow buttons, and while browsing ZDNet.com, I noticed that in their author bios, they have follow buttons for each author. Interestingly, the button would change according to who the author was. Here is an example: http://www.zdnet.com/blog/btl/sony-predicts-32-billion-loss-following-psn-hacking-japan-earthquake.

I tried copying the same idea on my blog LonePlacebo.com, with moderate success.

The code below is my author bio section using some PHP. I used some if statements to check the author, and it did produce the dynamic button as I was hoping for. However, it also output the author's name twice in plain text.

    <?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; ?>

Any help would be appreciated. Thanks!

Update I've tried updating the code so as to allow for more author's in the future. The call to get_author_meta() in the updated code below returns the info provided in the author's profile in the Twitter field. I want the code to display a default Follow button to @loneplacebo if the author has not provided any Twitter info, but if they did, display a button linking to their Twitter account.

Problem though is that if no Twitter account is provided, the code does to return the default button as expected. Any ideas how to solve this one?

<?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; ?>
  • 写回答

1条回答 默认 最新

  • duanchen1937 2011-06-04 05:06
    关注

    Instead of the_author() use get_the_author(). the_author() prints the name, latter returns the name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥20 关于#stm32#的问题:STM32串口发送问题,偶校验(even),发送5A 41 FB 20.烧录程序后发现串口助手读到的是5A 41 7B A0
  • ¥15 C++map释放不掉
  • ¥15 Mabatis查询数据
  • ¥15 想知道lingo目标函数中求和公式上标是变量情况如何求解
  • ¥15 关于E22-400T22S的LORA模块的通信问题
  • ¥15 求用二阶有源低通滤波将3khz方波转为正弦波的电路