麻烦与Wordpress漂亮的照片Pin It按钮

时间:2014-01-23 21:14:10

标签: php jquery wordpress javascript-framework prettyphoto

如果您转到http://jbrazeal.com/galleries/bridals,您可以在Wordpress主题中看到我的网站带有PrettyPhoto图库。默认情况下,当您单击图片时,图片会展开并为您提供“推文”或“喜欢”照片的选项,图片下方带有按钮。我安装了一个名为“prettyPhoto Media Pinterest”(https://github.com/Lawdawg/prettyphoto-media-pinterest)的插件,在其中为每个特定图片添加了“Pin It”按钮。

但是,该插件仅适用于某些页面,而不适用于其他页面。它适用于上面链接的页面,但它不适用于其他图库页面。例如,它不适用于页面/画廊/婚礼上的任何图片(我无法发布链接,因为我仅限于两个链接。

下面是PHP。我认为这是一个PHP问题,但如果你另有建议,我可以发布任何其他相关信息(该插件也有一个javascript文件)。此外,您可以看到我上面链接的实际网页和插件页面。谢谢!

<?php
add_action('init', 'ppm_pinterest_init');

function ppm_pinterest_init() {
    define('PPM_PINTEREST_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
    define('PPM_PINTEREST_VERSION', '0.1' );

    if (!is_admin()) {
            wp_enqueue_style('ppm_pinterest', PPM_PINTEREST_URI . 'css/ppm-pinterest.css', false, PPM_PINTEREST_VERSION, 'screen');
            wp_enqueue_script('pinterest_plus', PPM_PINTEREST_URI . 'js/pinterest-plus.min.js', false, false, true);
            add_action('wp_footer', 'ppm_pinterest_footer_script', 101);
    }        
}

function ppm_pinterest_footer_script() {
    $out = '<script>' . "\n";
    $out .= 'jQuery(function($) {' . "\n";        
    $out .= '  $(document).bind(\'DOMNodeInserted\', function(event) {' . "\n";
    $out .= '    if (window.settings && !window.settings.changepicturecallbackupdated) {' . "\n";
    $out .= '      window.settings.changepicturecallback = add_pinterest_pin_it_button' . "\n";
    $out .= '      window.settings.changepicturecallbackupdated = true;' . "\n"; 
    $out .= '    }' . "\n";
    $out .= '  });' . "\n";
    $out .= '});' . "\n";
    $out .= "\n";
    $out .= 'function add_pinterest_pin_it_button() {' . "\n";
    $out .= '  var i = jQuery(\'.pp_gallery\').find(\'li\').index(jQuery(\'.selected\'));' . "\n";
    $out .= '  var m = pp_images[i];' . "\n";
    $out .= '  jQuery(\'.pp_social\').append(\'<div class="pinterest"><a href="http://pinterest.com/pin/create/button/?url=\' + encodeURI(location.href.replace(location.hash,"")) + \'&media=\' + encodeURI(m) + \'" class="pin-it-button" count-layout="none"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a></div>\');' . "\n";
    $out .= '}' . "\n";
    $out .= '</script>' . "\n";

    echo $out;
}

?>

1 个答案:

答案 0 :(得分:0)

我明白了。你可以在这里查看我的插件分支,现在可以使用了!

https://github.com/Lawdawg/prettyphoto-media-pinterest

我将jQuery调用更改为:

    $out .= '  jQuery(\'.pp_social\').append(\'<div class="pinterest"><a target="_blank" href="http://pinterest.com/pin/create/button/?url=\' + encodeURI(location.href.replace(location.hash,"")) + \'&media=\' + encodeURI(m) + \'&description=\' + encodeURI(o) + \'" class="pin-it-button" count-layout="none"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a></div>\');' . "\n";
$out .= '}' . "\n";