WordPress.org

Forums

[resolved] Javascript in the sidebar - Codex didn't work (15 posts)

  1. ganzua
    Member
    Posted 10 years ago #

    This is my first post here, hi everybody!

    I want to include some javascripts in the sidebar of my custom template. I followed Codex instructions here; http://codex.wordpress.org/Using_Javascript

    I inserted this code in my template header.php between the meta tags and the style sheet link;

    <script type="text/javascript" src="/scripts/myscript.js"></script>

    Then, between <div></div> in the sidebar.php I inserted;

    <!--
    myscript();
    //--></script>

    My scripts are stored in a folder like this one;

    wp-content/themes/mytheme/scripts/myscript.js

    It didn't work. My browser is Ie. What am I doing wrong?

  2. brittanie
    Member
    Posted 10 years ago #

    Ganzua-

    What types of code are you trying to input. I mean, what does the JS do. Is it a counter or a Flickr badge or what?

    The reasono I ask is because I just went through the same thing last week trying to integrate TWO JSs to my site - a Flickr Badge in the sidebar and an invisible statcounter in the footer. I followed the instructions on the Codex and the bits of info I could piece together from the forums and nothing worked for me, even after several tried using the recommended method (i.e. "calling" the JS in using PHP). Eventually I just decided to put the raw JS into my sidebar, and tinkered with it, putting it into a list then a p class then a div class until finally it was XHTML valid (in a list). Same with the code in my footer.

    My site is here, if you want to view source to see what I did:
    http://abroad-abroad.org

    If you specify what type of JS your are trying to acheive, and include your url, maybe I can help.

  3. ganzua
    Member
    Posted 10 years ago #

    Hi brittanie;

    Thanks for your response. I have 3 javascripts that I'd like to put in the sidebar;

    * Quote of the day
    * Clock wich displays images depending on the date
    * Links Menu (I guess I can get rid of this one)

    I tried what you did; I put the raw JS into the sidebar and It worked ok.

    Nevetheless the "quote of the day" script is quite long, it has a quote for each day of the year. I think it should be better in a .js file.

  4. MC-Paladin
    Member
    Posted 10 years ago #

    I used a quote of the day javascript on my old site. When I converted to WordPress, (still running 1.2) I switched to the Witty plug-in. It's well documented and you can include html tags (<b>, <br>, <u>, etc) directly in your quotes. Plus (and I didn't find this out until recently, you can edit your quotes file directly from the plugins administration page in WordPress, so no more uploading a text file or adding lines to a Javascript.

    You can see Witty in action at the bottom of my page... http://paladin.gamingasylum.net and download it from the plugin's page here on wordpress.org.

  5. ganzua
    Member
    Posted 10 years ago #

    Thank you very much, MC-Paladin, I'll check the plug-in.

    However I have to find out what to do with the rest of my old js . Is this a matter of javascript compatibility with wordpress?

  6. brittanie
    Member
    Posted 10 years ago #

    However I have to find out what to do with the rest of my old js . Is this a matter of javascript compatibility with wordpress?

    If the js works, why not just use the other two scripts and then use the plug-in for quote of the day?

  7. MC-Paladin
    Member
    Posted 10 years ago #

    FYI... updated my site to 1.52 tonight, so ignore where I said I was running 1.2 in my earlier post. Witty continues to work with the updated version.

    I did misread what you were asking for, though. I didn't realize you had a single specific quote for each day. I'm not sure if Witty can be set up to do that or not, I use it to insert random quotes from a database and it changes the quote each time the page is refreshed, not per day. :(

  8. ganzua
    Member
    Posted 10 years ago #

    Brittanie, if I don't find out how to use js with wordpress I'll insert the raw code of all my old js as you suggested ;-) (quote of the day is more than 1000 lines long).

    MC-Paladin, I checked Witty, the idea is different but useful.

    This is a simple js from my old webpage. It displays the date (just an exmple);

    var currentTime = new Date()
    var day = currentTime.getDate()
    var month = currentTime.getMonth()
    var year = currentTime.getFullYear()
    document.write(day + "/" + month + "/" + year)

    Inserted as raw code between

    <script type="text/javascript" language="javascript">
    <!--

    Code...

    //-->
    </script>

    in the sidebar works.

    Calling the js file as codex says doesn't work. Nobody uses js with wordpress?

  9. billh
    Member
    Posted 10 years ago #

    How about the plugin from McMike? It's at:
    http://www.mcmike.nl/english/?page_id=6
    You simply put a php call where you wan the quote to show up. I used to use a javascript also; the plugin is much easier to locate in your code and much easier to manage.

  10. vkaryl
    Member
    Posted 10 years ago #

    True, billh, it's a real wonder and I like it INFINITELY better than witty.... but it won't OOB do what the OP wants, which is a specific post for each day....

    Or it won't right now. Hmmm. I might have to look at it from a different angle, because it would actually be pretty neat for some purposes of my own to have it do exactly what the OP is looking for....

  11. ganzua
    Member
    Posted 10 years ago #

    Thanks billh and vkaryl.

    Definitily I'll be using one of those plug-ins if I can't make js work. I have two options now; plug-ins or inserting js raw code.

  12. ganzua
    Member
    Posted 10 years ago #

    Ok, what is wrong with this calling;

    <script type="text/javascript" src="/scripts/myscript.js"></script>

    is that you need to provide the whole path; I mean http://....../myscript.js and you need to make the call in the header and in the sidebar.

    I have my old quote of the day java script running on the sidebar, but my old clock doesn't worck :(

  13. Mark (podz)
    Support Maven
    Posted 10 years ago #

    ganzua - can we have a link to your site ? It'll help us to help you.

  14. ganzua
    Member
    Posted 10 years ago #

    Hi Podz;

    My site it is not uploaded yet because I have to find hosting.

    I installed apache and mysql in my own computer and then I started to work in a custom template for wordpress, sorry.

  15. ganzua
    Member
    Posted 10 years ago #

    Ok, I solved this issue; I just included this calling in the sidebar;

    <script type="text/javascript" src="wp-content/themes/MyTheme/scripts/MyScripts.js"></script>

    It wasn't need a calling in the header.

    Now everything works. I'll post a link as soon as I upload my site. I have to solve other issues;

    * Replacing blogroll and pages headers for images
    * Creating a frontpage
    ...

    Thanks to everybody for your support!

Topic Closed

This topic has been closed to new replies.

About this Topic