获取 Twitter 按钮、计数和自定义 bit.ly URL 的方法,有效吗?
我被困住了。我将此发布于WordPress.StackExchange 他们建议我尝试 WebApps.StackExchange,他们建议我在这里试试。因此,如果您关注所有这些帖子,我对多篇帖子表示歉意!
我有一个客户博客,使用 bit.ly pro 生成自定义短网址(即 foo.co)。我想显示 Twitter 按钮的常规水平版本,以及推文计数,并让使用其自定义 bit.ly pro url 转到帖子的链接。
我已经安装了 Joost de Valk 的 Bit.ly Shortlinks 插件,它成功转换了普通的 WP 短链接( wp_get_shortlink()
) 到网站其他地方的自定义 Bit.ly pro URL,但 Twitter 似乎胜过了这一点,并使用默认的 t.co 域呈现所有内容。
我查看了这个问题 但使用 # 作为 data-url 不起作用,并且建议的 Twitter 支持页面似乎不包含任何有关如何让 Bit.ly 工作的信息(尽管他们说他们会这样做)。
这是我创建的用于在主题中插入按钮的函数 - 关于我哪里出错了有什么想法吗?这用于在循环和单帖子页面上插入按钮。
function tweet_this() {
global $post;
ob_start();
$tweet = wp_get_shortlink();
echo '<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><a href="http://twitter.com/share" class="twitter-share-button" data-url="' . $tweet . '" data-counturl="' . $tweet . '" data-count="horizontal" data-via="clietname" data-text="' . get_the_title() . '">Tweet</a>';
return ob_get_clean();
}
如果它有帮助的话,这个函数确实可以工作,只是它不渲染推文计数:
function tweet_this() {
global $post;
ob_start();
$tweet = sprintf( __('%1$s %2$s'), $post->post_title, wp_get_shortlink() );
echo '<a class="tweethis" href="http://twitter.com/intent/tweet?text=' . urlencode( $tweet ) . ' via @clientname">Tweet this</a>';
return ob_get_clean();
}
如果您需要更多信息,请告诉我 - 并提前感谢您为我提供的任何帮助! 米歇尔
I'm stuck. I posted this on WordPress.StackExchange and they suggested I try at WebApps.StackExchange, and they suggested I try here. So, apologies for the multiple posts if you follow all those!
I have a client blog using bit.ly pro to generate custom short urls (ie foo.co). I want to show the regular horizontal version of the Twitter button, with tweet-count, and have the link that goes to the post use their custom bit.ly pro url.
I have installed Joost de Valk's Bit.ly Shortlinks plugin, which successfully converts normal WP shortlinks (wp_get_shortlink()
) to the custom Bit.ly pro URL elsewhere in the site, but Twitter seems to trump that and render everything with the default t.co domain instead.
I've looked at the suggestions from this question but using the # as the data-url doesn't work, and the suggested Twitter support pages don't seem to contain any info on how to get Bit.ly to work (though they say they're going to).
Here's the function I created to insert the button in my theme - any ideas on where I'm going wrong? this is used to insert the button both within the Loop and on single-post pages.
function tweet_this() {
global $post;
ob_start();
$tweet = wp_get_shortlink();
echo '<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script><a href="http://twitter.com/share" class="twitter-share-button" data-url="' . $tweet . '" data-counturl="' . $tweet . '" data-count="horizontal" data-via="clietname" data-text="' . get_the_title() . '">Tweet</a>';
return ob_get_clean();
}
In case it helps, this function does work, except it doesn't render the tweet-count:
function tweet_this() {
global $post;
ob_start();
$tweet = sprintf( __('%1$s %2$s'), $post->post_title, wp_get_shortlink() );
echo '<a class="tweethis" href="http://twitter.com/intent/tweet?text=' . urlencode( $tweet ) . ' via @clientname">Tweet this</a>';
return ob_get_clean();
}
Let me know if you need more info - and thanks in advance for any help you can throw my way!
Michelle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用,但我没有安装 WPShortlinks,所以我用永久链接替换了它。您应该能够用 wp_get_shortlink 替换永久链接,并且它应该可以工作。
This works for me, but I don't have the WPShortlinks installed, so I replaced it with the permalink. You should be able to replace the permalink with your wp_get_shortlink and it should work.