0

有没有办法让 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>

Just wonder if this is something that someone has already figured out or not? Would be nice if this could work that way, will make life simple.

Thanks in advance for any help you can offer!

4

1 回答 1

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>

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

于 2012-12-09T17:03:59.327 回答