简体   繁体   English

在Wordpress子主题中覆盖JavaScript函数

[英]Overriding a javascript function in a Wordpress Child Theme

I am writing a simple Wordpress child theme. 我正在写一个简单的Wordpress儿童主题。

There is a portfolio feature which uses flexslider to display the thumbnail from the most recent posts and, when clicking on them, it uses ajax to open up the post content in a div on the page. 有一个组合功能,它使用flexslider来显示最新帖子的缩略图,单击它们时,它使用ajax在页面的div中打开该帖子的内容。

I have written a category page based on this, which pulls out all the post categories and displays the thumbnail for the most recent post. 我基于此编写了一个类别页面,该页面可以拉出所有帖子类别并显示最新帖子的缩略图。 However, when I click on the thumbnail, I need the page to go to a new page and not open up in the content div. 但是,当我单击缩略图时,我需要页面转到新页面,而不在内容div中打开。

The problem is, I am reusing code which looks a bit like this: 问题是,我正在重用看起来像这样的代码:

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <div class="flexslider">
            <ul class="slides">
                <li>
                    <a href="http://the-url-here">
                        <img src="<?php  echo $thumb[0]; ?>" />
                    </a>
                </li>
            </ul>
    </div>
<?php endwhile; ?>

But there is custom js within the parent theme global footer as follows which handles the opening up of the content, rather than redirecting to the location specified in the tag as usual. 但是,在父主题全局页脚中有如下自定义js,它处理内容的打开,而不是像往常一样重定向到标记中指定的位置。

$(".flexslider ul.slides li a").live('click', function(e){ e.preventDefault();

   /*Set Function Variables */       
    $this = $(this);
    $selectedthing = $this;
    $postId = $($this).attr('data-url');

    // and so on...

    return false; 
});

So, I need to disable the javascript attached to .flexslider ul.slides li a on that one single page template only , preferably without having to change the classes, as I think thatwould open up another can of worms around the css. 因此,我需要仅在单个页面模板上禁用附加到.flexslider ul.slides li a上的javascript ,最好不必更改类,因为我认为这会在css周围打开另一蠕虫病毒。 Remember the theme loads the javascript in the footer, so I assume any changes Imake in the page template will be overridden in the footer. 请记住,主题在页脚中加载了javascript,因此我假设页面模板中对Imake所做的任何更改都将在页脚中被覆盖。

Any ideas on the best way to approach this? 对解决此问题的最佳方法有任何想法吗?

Just remove click live listener in your child theme. 只需在您的子主题中删除点击实时监听器即可。 Add this javascript only for that specific page template. 仅针对该特定页面模板添加此javascript。

$(".flexslider ul.slides li a").die('click');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM