2013-04-20 101 views
1

我试图在我的wordpress网站上实现“Tweet”按钮,并且在推文中没有显示URL。Twitter按钮没有显示Tweet的网址

它显示哈希标签和帐户,但不显示URL。

我的代码如下:

<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php echo urlencode(get_permalink($post->ID)); ?>" data-via="mixtapes_4_free" data-related="realdannys" data-hashtags="mixtape">Tweet</a> 

如果我不使用data-url那么它只是插入底座的域名,而不是完整的URL。

任何想法?

回答

1

您是否尝试过推特页面上的代码?看看twitter API here

+0

谢谢......这个页面确实有帮助。 – 2013-04-20 22:16:15

1

您正在提交查询代码。

你可能有你的代码HERE

分享一个链接,JavaScript代码是

<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> 

你的锚标记后只需添加该代码。

+0

谢谢......虽然这并没有解决我的问题,但确实让我朝着正确的方向前进。 – 2013-04-20 22:15:09

1

我有下面的代码:

<a href="<?php echo $tweet_url; ?>" class="twitter-share-button" data-url="=<?php the_permalink(); ?>" data-via="<?php echo of_get_option('ac_twitter_username'); ?>" data-lang="en" data-related="anywhereTheJavascriptAPI" data-count="vertical">Tweet</a> 
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> 

但没有工作,所以我试图简化版本:

<a href="http://twitter.com/share?url=<?php echo urlencode(wp_get_shortlink()); ?>&amp;counturl=<?php urlencode(the_permalink()); ?>" class="twitter-share-button" data-count="vertical" data-via="<?php echo of_get_option('ac_twitter_username'); ?>">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> 

而这一次的工作就好了。只要记住,该用户名必须以某种方式集成在你的主题设置,如果没有的话,你可以改变:

<?php echo of_get_option('ac_twitter_username'); ?> 

为了您的Twitter用户名。

我希望这有效,我花了一段时间才找到这个更通用的方法。我不完全知道我在做什么,所以如果有人看到这个方法的问题,请让我知道。到目前为止,它工作得很好。

谢谢!