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,154
    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
    117
    Plugin Contributions
    12

    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. custom jQuery Mobile formatting issue for product info
    By smm11 in forum General Questions
    Replies: 3
    Last Post: 11 Jan 2012, 08:13 PM
  2. Run custom script only after successful checkout
    By urgentprog in forum General Questions
    Replies: 6
    Last Post: 1 Jul 2011, 01:25 PM
  3. Can I run my store in a custom iframe?
    By djjonex in forum General Questions
    Replies: 2
    Last Post: 28 Jun 2011, 04:51 PM
  4. sorting product lists with jquery (query category names to div classes)?
    By poosk in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 23 Mar 2011, 08:39 AM
  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
  •