Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Jul 2007
    Location
    Jakarta
    Posts
    358
    Plugin Contributions
    0

    Default including jscript*.php file in category description

    I'm trying to optimize my site.

    One way of doing this is to move *.js scripts that don't need to be global to specific pages.

    I have a jscript_wimpy.js (a video player) that I want to convert to jscript_wimpay.php.

    I used the js file and copied it adding <script> at the beginning and </script> at the end.

    I then put

    Code:
    <?php include "includes/templates/{my_template_directory}/jscript/jscript_wimpy.php"; ?>
    in my html of the category description.

    This must not be the correct technique because it doesn't work.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: including jscript*.php file in category description

    You're making it more complicated than it needs to be.

    http://www.zen-cart.com/wiki/index.p...s_-_Javascript
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jul 2007
    Location
    Jakarta
    Posts
    358
    Plugin Contributions
    0

    Default Re: including jscript*.php file in category description

    Quote Originally Posted by DrByte View Post
    You're making it more complicated than it needs to be.

    http://www.zen-cart.com/wiki/index.p...s_-_Javascript
    Thanks Dr. Byte, for trying to help.

    But what I did was gleemed from the same intructions gaven in the link.

    Where am I going wrong? I only want this particular js to load for the particular category.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: including jscript*.php file in category description

    Quote Originally Posted by shocker View Post
    I have a jscript_wimpy.js (a video player) that I want to convert to jscript_wimpay.php.

    I used the js file and copied it adding <script> at the beginning and </script> at the end.

    I then put

    Code:
    <?php include "includes/templates/{my_template_directory}/jscript/jscript_wimpy.php"; ?>
    in my html of the category description.
    1. If you've put a jscript_xxxx.php or jscript_xxxx.js file in the /includes/templates/{your_template}/jscript folder, then it's going to load on every page automatically.
    So, adding it to your category description serves no useful purpose.

    2. Adding PHP code (ie: <?php include ...... ?> ) to the html of a category description will do nothing, since Zen Cart doesn't process embedded PHP instructions contained in category descriptions.

    3. If you only want the script to run when looking at category listings, stick the jscript_xxxxx.js file in your /includes/modules/pages/index/ folder. It'll load for all categories, but not for other pages such as checkout or shopping-cart, etc.

    4. An alternative to #3 above would be to use a jscript_xxxx.php file (instead of .js) and wrap some PHP code (perhaps an IF statement) around the usual contents, which checks to see whether a certain cPath has been specified, and only send the script to the browser if the certain category (cPath) is selected.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Jul 2007
    Location
    Jakarta
    Posts
    358
    Plugin Contributions
    0

    Default Re: including jscript*.php file in category description

    Quote Originally Posted by DrByte View Post

    4. An alternative to #3 above would be to use a jscript_xxxx.php file (instead of .js) and wrap some PHP code around the usual contents which check to see whether a certain cPath has been specified, and only send the script to the browser if the certain category (cPath) is selected.
    For now #4 is what I want to do.
    I guess I can conditionally add the include statement if the cPath is the one I want. I currently looking at tpl_main_page.php. Where to do suggest I implement this condition check?

    Eventually what I want is an EZ-page that has certain instructional videos on it. I only want the js code loaded for this page. Can I put the jscript_xxxx.php include in the text html of the EZ-page? this just seems easier.

  6. #6
    Join Date
    Jul 2007
    Location
    Jakarta
    Posts
    358
    Plugin Contributions
    0

    Default Re: including jscript*.php file in category description

    I'm planning on adding the code below to tpl_main_page.php. Will SEO rewrites prevent this from working? do I have to add code for this to. I'm new to SEO so I'm not very clear on how it works and what it does in relation to what ZenCart standard does.

    Code:
    if ($current_page_base == 'index' and $cPath == '2') {
        echo "include/..../jscript_XXXX.php";
        }

    Where should the jscript_XXXX.php be placed in order to not interfere with anything and not load other than where I want?

  7. #7
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: including jscript*.php file in category description

    If you go back and read the wiki article, you'll see that if you put the jscript_xxxx.php or .js file in the correct folder, it will automatically load for you.
    You DO NOT need to "include" it anywhere at all.

    That's why I said to put it into the /includes/modules/pages/index/ folder.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: including jscript*.php file in category description

    As to customizing it to load just for a certain category, here's what I meant in my #4 suggestion earlier:


    /includes/modules/pages/index/jscript_mywimpyplayerscript.php
    Code:
    <?php
    if ($cPath== '3_10') {
    ?>
    <script type="text/javascript" language="javascript">
    
    ....copy and paste wimpy.js code here
    
    
    </script>
    <?php } ?>
    Change '3_10' to whatever the right cPath is for the one category you're limiting it to.

    That's it. Put the file in the place specified. Leave your descriptions alone. No other coding needed.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Jul 2007
    Location
    Jakarta
    Posts
    358
    Plugin Contributions
    0

    Default Re: including jscript*.php file in category description

    Quote Originally Posted by DrByte View Post
    If you go back and read the wiki article, you'll see that if you put the jscript_xxxx.php or .js file in the correct folder, it will automatically load for you.
    You DO NOT need to "include" it anywhere at all.

    That's why I said to put it into the /includes/modules/pages/index/ folder.
    Does this apply to #4 in your previous post #4? If so, I dont' know how to "send the script to the browser" other that my attempt in post #6

  10. #10
    Join Date
    Jul 2007
    Location
    Jakarta
    Posts
    358
    Plugin Contributions
    0

    Default Re: including jscript*.php file in category description

    Please forgive me for belaboring this point.

    I got it. Leave description alone.

    Everything is clear except...
    my question is if I only want the code loaded for one page (category description) why do I need to put the file in the index/ folder also?

    If I'm pasting js code directly into the tpl_main_page.php, do I still need the file at all?

    Thanks for your time

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Need help adding a JSCRIPT file
    By kelly60 in forum General Questions
    Replies: 4
    Last Post: 1 Feb 2014, 11:09 PM
  2. Where is PHP file for Product Description?
    By jack911 in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 3 Jul 2011, 11:23 PM
  3. product description in which php file?
    By charliepingpong in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 2 Jun 2011, 07:42 AM
  4. What File category description resided
    By Rideright in forum General Questions
    Replies: 2
    Last Post: 27 Nov 2007, 04:13 PM

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