• Im trying to run a bit of javascript code ( which creates a basic thumbnail layout ) on a custom page template within my theme.

    Page template is called page-showcase.php
    Javascript file called makethumbs.js

    Calling the js file in the Header.php just after php wp_head() like this:

    <script type=”text/javascript” src=”makethumbs.js”></script>

    Then in the page-showcase.php i`m calling the function like so:

    <em>[Code moderated as per the <a href=”http://codex.wordpress.org/Forum_Welcome#Posting_Code”>Forum Rules</a>. The maximum number of lines of code that you can post in these forums is <strong>ten lines</strong>. Please use the <a href=”http://wordpress.pastebin.com/”>pastebin</a>%5D</em&gt;

    This isnt working at all. Hitting F12 in Chrome and looking at loaded scripts theres no mention of my makethumbs.js file.. so it`s not loading i think is the problem. The js file is stored in the same folder as Header.php etc etc..

    Any help would be much appreciated!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Where did you put the makethumbs.js? What is the path?

    <script type=”text/javascript” src=”<?php bloginfo(url);?>/path from website root/makethumbs.js”></script>

    Thread Starter Knipple

    (@knipple)

    As i said in the post the js file is in the same folder as the Header and template files etc ( root of the twentyeleven theme )..

    In that case, the correct code is:

    <script type=”text/javascript” src=”<?php bloginfo(template_directory);?>/makethumbs.js”></script>

    Thread Starter Knipple

    (@knipple)

    That’s not making any difference, thanks though. If there’s no path it’d just reference the same folder it’s running out of tho right?

    Thread Starter Knipple

    (@knipple)

    Any idea why the text in my replies on here are showing up in mixed fonts??

    Because you keep using backticks instead of single quotation marks. Backticks are used by the forum’s parser to indicate code blocks.

    Thread Starter Knipple

    (@knipple)

    U on about something in the code whats a back tick?

    A single quotation mark looks like this -> ‘. You are using a grave accent.

    Thread Starter Knipple

    (@knipple)

    Ahh the punctuation in my text?? So if i wrote it’s i have to use the straight one rather than the backwards tilted one.. why doesn`t the code button wrap it in a proprietary code tag like normal forums?

    So if i wrote it’s i have to use the straight one rather than the backwards tilted one

    Correct.

    why doesn`t the code button wrap it in a proprietary code tag like normal forums?

    The backtick is classed as a proprietary code tag here.

    Thread Starter Knipple

    (@knipple)

    It’s quite a pointless one then isn’t it, if it conflicts with standard text / can’t differentiate.

    Chome is now showing ‘Uncaught Reference Error: makethumbs is not defined’ on the debug. It`s being thrown at the following code in the template page:

    <script type="text/javascript">
    <!--
    	makethumbs();
    
    Uncaught ReferenceError: makethumbs is not defined
    //-->
    </script>

    It doesn`t seem to be complaining about can’t find the script now so no idea..

    [No bumping. If it’s that urgent, consider hiring someone.]

    Thread Starter Knipple

    (@knipple)

    Okay i got this working, it was basically an url/location as Flashbuddy pointed out. Notice the kindof curly speechmarks in your code Flashbuddy? That’s what was throwing it and i hadn’t noticed..

    I have a fresh new problem – in my external js file i’m trying to use the template url in javascript using the php command:

    var backgroundUrl = "<?php bloginfo(template_directory);?>" + "/images/thumbs/" + numThumbs + ".jpg";
    
    alert(backgroundUrl);
    
    newdiv.style.backgroundImage ="url("+backgroundUrl+")";

    But the php code doesn’t seem to be giving the url, it’s just printing the php code..

    Any hints/tips?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘JS in page template..’ is closed to new replies.