开发者

Dynamic Twitter Follow button

开发者 https://www.devze.com 2023-03-10 03:25 出处:网络
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 c

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 end开发者_运维问答if; ?>                     
                        <!--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; ?>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消