简体   繁体   English

在一个js文件中为不同的wordpress页面添加多个自定义脚本

[英]Add multiple custom script in one js file for different wordpress page

I have written this script in a scripts.js file. 我已将此脚本编写在scripts.js文件中。 And I want execute the first half for only Home page and second half for custom post type page. 我只想对首页执行上半部分,对自定义帖子类型页面执行下半部分。 How can I do this in wordpress ? 如何在Wordpress中执行此操作?

 // This Chunk For Home Page  [Part one]
 jQuery("#front-page-slider").responsiveSlides({
              maxwidth: 390,
              "auto": true,
              "pager": false,
               "nav": false,
              "pause": true,
               speed: 800
          });



    // This Chunk is for For Only Custom Post Page [Part Two]
  $("a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',theme:'pp_default',slideshow:3000, autoplay_slideshow: false});
  var width = $(window).width();

如注释中所建议,您可以利用body类,例如:

if(jQuery('body.home').length){alert('home');}

this is my idea: 这是我的主意:

in the js: 在js中:

function PartOneForHome(){
//code bla bla bla
}
function PartTwoForCustomPosts(){
//code bla bla bla
}

in the header.php or footer.php: 在header.php或footer.php中:

<?php if(is_home()) { ?>
  <script> PartOneForHome(); </script>
<?php } else if is any custom post* { ?>
  <script> PartTwoForCustomPosts(); </script>
<?php } ?>

*I dont know how to detect if is a custom post, search for it :D *我不知道如何检测是否是自定义帖子,请搜索它:D

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

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