2013-04-20 34 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用戶名。

我希望這有效,我花了一段時間才找到這個更通用的方法。我不完全知道我在做什麼,所以如果有人看到這個方法的問題,請讓我知道。到目前爲止,它工作得很好。

謝謝!