Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    19
    Plugin Contributions
    0

    Default Run Custom Jquery for a particular category

    Hello,

    I have a category that has an iframe. I've been able to apply some custom styling to that category by creating a new stylesheet: c_28_34.css, this works very well.

    I also want to run a bit of custom Jquery code, specific to this category.

    Is it possible to create a custom script that only applies to a certain category ?

    Regards,
    Stephen

  2. #2
    Join Date
    Nov 2009
    Location
    UK
    Posts
    1,090
    Plugin Contributions
    0

    Default Re: Run Custom Jquery for a particular category

    Cant you just call the Jquery from the category description html so it only runs on that cat?

  3. #3
    Join Date
    Apr 2012
    Posts
    19
    Plugin Contributions
    0

    Default Re: Run Custom Jquery for a particular category

    Yes, I could do that alright, thanks for the reply.

  4. #4
    Join Date
    Jun 2008
    Location
    Osprey, Florida
    Posts
    151
    Plugin Contributions
    14

    Default Re: Run Custom Jquery for a particular category

    Quote Originally Posted by stephenconnolly View Post
    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...

 

 

Similar Threads

  1. Replies: 15
    Last Post: 24 Feb 2014, 06:23 PM
  2. v139h Custom Product Page - for particular product - use separate template
    By boxes in forum Templates, Stylesheets, Page Layout
    Replies: 11
    Last Post: 4 Dec 2012, 10:05 PM
  3. custom jQuery Mobile formatting issue for product info
    By smm11 in forum General Questions
    Replies: 3
    Last Post: 11 Jan 2012, 08:13 PM
  4. Disable a particular sidebox for a particular page?
    By surabisantosh in forum Basic Configuration
    Replies: 1
    Last Post: 22 Nov 2007, 08:04 PM
  5. Replies: 3
    Last Post: 18 Mar 2007, 10:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR