如何在个人帖子中实现自定义按钮?

时间:2015-06-19 作者:A-Aron Campbell

有没有什么方法可以在wordpress上为个人帖子的喜欢、分享和推特定制按钮。如果是这样,我将如何将“喜欢”按钮链接到Facebook上的“喜欢”帖子,以及如何链接“共享”和“推特”按钮。

1 个回复
SO网友:Nita

以下是添加自定义共享按钮的简单方法(只需将此代码放置在您希望显示共享按钮的位置):

<?php
$twitter_username = \'your_twitter_username\';
$shortURL = esc_url(get_permalink());
$shortTitle = esc_attr(get_the_title());
$imgURL = wp_get_attachment_url( get_post_thumbnail_id() );
$twitterURL = \'https://twitter.com/intent/tweet?text=\'.$shortTitle.\'&amp;url=\'.$shortURL.\'&amp;via=\'.$twitter_username;
$facebookURL = \'https://www.facebook.com/sharer/sharer.php?u=\'.$shortURL;
$googleURL = \'https://plus.google.com/share?url=\'.$shortURL; 
$pinURL = \'http://pinterest.com/pin/create/button/?url=\'.$shortURL.\'&media=\'.$imgURL.\'&description=\'.$shortTitle;
?>

<a class="facebook-btn" href="<?php echo $facebookURL; ?>" target="_blank" onclick="window.open(\'<?php echo $facebookURL; ?>\', \'popupwindow\', \'scrollbars=no,width=500,height=400\');return true">Share on Facebook</a>
<a class="google-btn" href="<?php echo $googleURL; ?>" target="_blank" onclick="window.open(\'<?php echo $googleURL; ?>\', \'popupwindow\', \'scrollbars=no,width=500,height=400\');return true">Share on Google Plus</a>
<a class="twitter-btn" href="<?php echo $twitterURL; ?>" target="_blank" onclick="window.open(\'<?php echo $twitterURL; ?>\', \'popupwindow\', \'scrollbars=no,width=500,height=300\');return true">Tweet on Twitter</a>
<a class="pinterest-btn" href="<?php echo $pinURL; ?>" target="_blank" onclick="window.open(\'<?php echo $pinURL; ?>\', \'popupwindow\', \'scrollbars=no,width=700,height=500\');return true">Pin on Pinterest</a>
现在,您需要做的是为这些类添加一些样式:

.facebook-btn

.google-btn

.twitter-btn

.pinterest-btn
希望这对你有帮助。

结束