我的网站上有博客页面上列出的文章,我希望有一个自定义的Facebook分享,Tweet This&为每篇文章分配的电子邮件链接以下是Twitter链接的代码:
<a href=\"https://twitter.com/share\" data-url=\"http://www.mywebsite.co.uk?article=$article_id\"><div class=\"shareCell shareTwitter\"></div></a>
问题在于,当我点击推文图片时,它会尝试共享主要博客页面而不是相关文章 - 任何想法为什么或如何对其进行排序。
此外,如何对Facebook进行同样的操作并直接通过电子邮件发送文章?
答案 0 :(得分:0)
你已经逃过了整个HTML,我怀疑你使用的是php。
<a href=\"https://twitter.com/share\" data-url=\"http://www.mywebsite.co.uk?article=$article_id\"><div class=\"shareCell shareTwitter\"></div></a>
应该是:
<a href=\"https://twitter.com/share\" data-url=\"http://www.mywebsite.co.uk?article=" . $article_id . "\"><div class=\"shareCell shareTwitter\"></div></a>
$ article_id是来自php的变量
对于facebook,这里有一个非常类似的方法:https://developers.facebook.com/docs/plugins/share-button/
并发送电子邮件:
<a href="mailto:emailname@yourdomain.com?subject=encodeURIComponent('Check out the blogpost http://www.mywebsite.co.uk?article=" . $article_id . "');">Send in email</a>
答案 1 :(得分:0)
<script>
function fb_share(url)
{
var url = 'http://www.facebook.com/sharer.php?u=' +encodeURIComponent('<?php echo full_path();?>'+url);
window.open(url, 'Share on FaceBook', 'left=20,top=20,width=550,height=400,toolbar=0,menubar=0,scrollbars=0,location=0,resizable=1');
return false;
}
</script>
&#13;
//first upon put this given below php code in ur header or top of the page.
<?php
function full_path()
{
$s = &$_SERVER;
$ssl = (!empty($s['HTTPS']) && $s['HTTPS'] == 'on') ? true:false;
$sp = strtolower($s['SERVER_PROTOCOL']);
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
$port = $s['SERVER_PORT'];
$port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
$host = isset($s['HTTP_X_FORWARDED_HOST']) ? $s['HTTP_X_FORWARDED_HOST'] : (isset($s['HTTP_HOST']) ? $s['HTTP_HOST'] : null);
$host = isset($host) ? $host : $s['SERVER_NAME'] . $port;
$uri = $protocol . '://' . $host . $s['REQUEST_URI'];
$segments = explode('?', $uri, 2);
$url = $segments[0];
return $url;
}
?>
// This is the part of HTML Portion that you need to be included in your article section
<a href="javascript:fb_share('?article=1')">Share this on Facebook</a>
&#13;