Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未定义变量&;尝试获取图像函数的前置按钮上非对象的属性_Javascript_Jquery_Wordpress_Function - Fatal编程技术网

Javascript 未定义变量&;尝试获取图像函数的前置按钮上非对象的属性

Javascript 未定义变量&;尝试获取图像函数的前置按钮上非对象的属性,javascript,jquery,wordpress,function,Javascript,Jquery,Wordpress,Function,我在我的单篇文章中为我的Wordpress图片预先添加了一个按钮,以便在Pinterest上共享这些图片。到目前为止,该函数运行良好,但我收到以下通知 注意:未定义变量:post in…functions.php on 第2443行注意:尝试获取 第2443行/functions.php中的非对象 通知中提到的行是以$开头的行(this)。prepend(.. 你知道如何解决这个问题吗? 使用的功能: <?php if ( is_single() ) : ?> <script

我在我的单篇文章中为我的Wordpress图片预先添加了一个按钮,以便在Pinterest上共享这些图片。到目前为止,该函数运行良好,但我收到以下通知

注意:未定义变量:post in…functions.php on 第2443行
注意:尝试获取 第2443行/functions.php中的非对象

通知中提到的行是以
$开头的行(this)。prepend(..

你知道如何解决这个问题吗?

使用的功能:

<?php if ( is_single() ) : ?>

<script type="text/javascript">
jQuery(document).ready(function($) {
    $('figure').prepend(function(){
        var pinurl = $(this).children('img').attr('data-original'); // with lazy load
        // var pinurl = $(this).children('img').attr('src'); // default
        $(this).prepend( '<a class="share-pinterest-btn" title="Pinterest" rel="nofollow" target="_blank" href="https://www.pinterest.com/pin/create/bookmarklet/?url=<?php echo urlencode(get_permalink($post->ID)); ?>&media='+pinurl+'&is_video=false&description=<?php echo urlencode(get_the_excerpt()); ?>" onclick="window.open(this.href, \'mywin\',\'left=50,top=50,width=600,height=350,toolbar=0\'); return false;">Pin it</a>');
    });
});
</script>

<?php else : ?>

     // something else

<?php endif; ?>

jQuery(文档).ready(函数($){
$('figure').prepend(函数(){
var pinurl=$(this).children('img').attr('data-original');//使用延迟加载
//var pinurl=$(this).children('img').attr('src');//默认值
$(this.prepend(“”);
});
});
//别的
HTML看起来像:

<figure id="post-881 media-881" class="align-none"><img alt="" data-original="http://teststestests.com/wp-content/uploads/2017/1.jpg" class="loaded" src="http://teststestests.com/wp-content/uploads/2017/1.jpg"></figure>



然后你的javascript代码

那么你在哪里定义了
$post
对象呢?我试图将
global$post;
放入函数中-但是没有运气。如果你的意思是其他的-我不幸无法修复它-仍在阅读wordpress docsperfect-非常感谢!我已经将
global$post;
放入函数中了没有运气的离子:)
<?php
if(is_single()) : 
global $post;
?>