Pin It Button,它可以与OG一起使用,就像Facebook或G +一样吗?

时间:2012-12-09 12:54:50

标签: button plugins pinterest

有没有办法让Pin It按钮与OG一起使用

<a href="http://pinterest.com/pin/create/button/?url=["pull from OG"]&media=["Pull from OG"]&description=["Pull from OG"]" class="pin-it-button" count-layout="vertical"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
<script type="text/javascript">
(function (w, d, load) {
 var script,
 first = d.getElementsByTagName('SCRIPT')[0],  
 n = load.length,
 i = 0,
 go = function () {
   for (i = 0; i < n; i = i + 1) {
     script = d.createElement('SCRIPT');
     script.type = 'text/javascript';
     script.async = true;
     script.src = load[i];
     first.parentNode.insertBefore(script, first);
   }
 }
 if (w.attachEvent) {
   w.attachEvent('onload', go);
 } else {
   w.addEventListener('load', go, false);
 }
}(window, document,
 ['//assets.pinterest.com/js/pinit.js']
));    
</script>

只是想知道这是否是某人已经想到的东西?如果能够以这种方式工作会很好,会让生活变得简单。

提前感谢您提供的任何帮助!

1 个答案:

答案 0 :(得分:0)

以下是我所做的工作,但不确定这是否是最好的方法,因为它需要使用php echo来回显开放图元元素内容。

<meta property="og:title" content="Family Budget Spreadsheet for Excel"> 
<meta property="og:type" content="product"> 
<meta property="og:url" content="<?php $og_url = $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; echo $og_url ?>"> 
<meta property="og:image" content="<?php $og_image = 'http://www.mysite.com/images/imageIneed.jpg' ; echo $og_image ?>">
<meta property="og:site_name" content="My Sites Name"> 
<meta property="og:description" content="<?php $og_description = 'My page description'; echo $og_description ?>">

然后添加以下代码来自Pinterest

<a href="http://pinterest.com/pin/create/button/?url=<?php echo $og_url ?>&media=<?php echo $og_image ?>&description=<?php echo $og_description ?>" class="pin-it-button" count-layout="vertical"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
<script type="text/javascript">
(function (w, d, load) {
 var script,
 first = d.getElementsByTagName('SCRIPT')[0],  
 n = load.length,
 i = 0,
 go = function () {
   for (i = 0; i < n; i = i + 1) {
     script = d.createElement('SCRIPT');
     script.type = 'text/javascript';
     script.async = true;
     script.src = load[i];
     first.parentNode.insertBefore(script, first);
   }
 }
 if (w.attachEvent) {
   w.attachEvent('onload', go);
 } else {
   w.addEventListener('load', go, false);
 }
}(window, document,
 ['//assets.pinterest.com/js/pinit.js']
));    
</script>

工作正常,但我确信有更好的方法可以做到这一点,所以如果你有一个,请在这里分享。