Originally Posted by
stephenconnolly
Is it possible to create a custom script that only applies to a certain category ?
You have several options to run jQuery scripts for a specific category. More specifically the jQuery…
It may seem as if I'm getting of the subject but give me a chance to explain.
If you are running jQuery site wide, I would use the following code to grab jQuery from Google with a fallback if necessary:
Code:
<!-- grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<?php echo '<script type="text/javascript" src="' . DIR_WS_TEMPLATE . 'jscript/libs/jquery/1.7.1' . '/jquery-1.7.1.min.js"><\/script>'; ?>')</script>
You could add the above code to a new file named jscript_whatever.php adding it to the script folder of your custom template or even better in my opinion, add this code to your html_header.php and add it to the common folder of your custom template. Keep in mind that jQuery has to run before any "jQuery" scripts therefore, if modifying html_header.php, place it immediately after the last code for css.
You can then add a conditional code for your category to a jscript_whatever.php in your custom script folder:
Code:
<?php if ($current_page_base == 'index' and $cPath == '' or $cPath == '3') { ?>
<script type="text/javascript">
$(document).ready(function () {
// Your Code Goes Here
});
</script>
<?php } ?>
If you are running jQuery only for that category simply combine what I just talked about to again a jscript_whatever.php in the following manner:
Code:
<?php if ($current_page_base == 'index' and $cPath == '' or $cPath == '3') { ?>
<!-- grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<?php echo '<script type="text/javascript" src="' . DIR_WS_TEMPLATE . 'jscript/libs/jquery/1.7.1' . '/jquery-1.7.1.min.js"><\/script>'; ?>')</script>
<script type="text/javascript">
$(document).ready(function () {
// Your Code Goes Here
});
</script>
<?php } ?>
Hope that helps...
Bookmarks