5 Replies - 1645 Views - Last Post: 19 August 2007 - 03:37 PM

#1 photographworks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-July 07

Can I and if so how do I put this javascript in Wordpress page of php?

Post icon  Posted 29 July 2007 - 11:51 PM

I have a domain name and a host. I would like to use wordpress for the site. I want to use Amazon context links and this is the script (ID changed to protect the innocent) below.

The function of the javascript is as follows. It identifies words in the text that correspond to items that Amazon sells. When the reader hovers over the text, the link to the product shows itself in a little box.

I see that wordpress pages are written in php and I have no idea whether it is possible to insert this javascript and make it work, or, if it is possible, which pages to insert the script into.

I am a beginner-beginner.

<script type="text/javascript"><!--
amzn_cl_tag="exampleID";
//--></script>
<script type="text/javascript" src="http://cls.assoc-amazon.co.uk/gb/s/cls.js"></script>


thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Can I and if so how do I put this javascript in Wordpress page of php?

#2 Addiction2Code  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 19-December 06

Re: Can I and if so how do I put this javascript in Wordpress page of php?

Posted 01 August 2007 - 11:30 AM

If your trying to output javascript in PHP you would just echo it, I don't really get what your asking, But to have the php display javascript you would use some output function like echo.
Was This Post Helpful? 0
  • +
  • -

#3 photographworks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-July 07

Re: Can I and if so how do I put this javascript in Wordpress page of php?

Posted 03 August 2007 - 08:16 AM

Thanks for the reply. I am sorry my original question is unclear. I will try to explain more clearly.

The function of the javascript is to somehow identify words used in the text as relevant to products that amazon sell.

If you look the Blogger blog at http://digitaladvice.blogspot.com/ you will see that on the fourth line of the first paragraph, the word 'SLR' is in blue. If you hover your curser over the word, a little amazon box opens.

I put that script into the blog html. It was easy because the page was written in html.

I also have blogs hosted on commercial servers and these blogs are built using wordpress. Wordpress is written in php, and I want to inset the javascript into the relevant pages so that the javascript does the same thing that it does in the Blogger blog.

If it will work with 'echo', how do I do it?
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Can I and if so how do I put this javascript in Wordpress page of php?

Posted 05 August 2007 - 01:16 AM

View Postphotographworks, on 3 Aug, 2007 - 08:16 AM, said:

If it will work with 'echo', how do I do it?


Adding Javascript in a PHP page using echo is done like this

<?
echo "<script language=\"Javascript\">\n";
echo "alert("You just used echo to add Javascript");\n";
echo "</script>";
?> 



inside the <script> tags, you would, of course, have your Javascript code not my simple alert message :)

Hope this helps

Happy Coding!

This post has been edited by PsychoCoder: 05 August 2007 - 01:17 AM

Was This Post Helpful? 0
  • +
  • -

#5 photographworks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-July 07

Re: Can I and if so how do I put this javascript in Wordpress page of php?

Posted 19 August 2007 - 12:44 PM

View PostPsychoCoder, on 5 Aug, 2007 - 01:16 AM, said:

View Postphotographworks, on 3 Aug, 2007 - 08:16 AM, said:

If it will work with 'echo', how do I do it?


Adding Javascript in a PHP page using echo is done like this

<?
echo "<script language=\"Javascript\">\n";
echo "alert("You just used echo to add Javascript");\n";
echo "</script>";
?> 



inside the <script> tags, you would, of course, have your Javascript code not my simple alert message :)

Hope this helps

Happy Coding!



Dear PC
Thanks, it helps but doesn't quite get me there. Could you show me by copying the stuff I put in my original post, into the code you used, so I can see exactly where it goes?

thanks
David
Was This Post Helpful? 0
  • +
  • -

#6 formalsleek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 25-November 05

Re: Can I and if so how do I put this javascript in Wordpress page of php?

Posted 19 August 2007 - 03:37 PM

View Postphotographworks, on 19 Aug, 2007 - 12:44 PM, said:

View PostPsychoCoder, on 5 Aug, 2007 - 01:16 AM, said:

View Postphotographworks, on 3 Aug, 2007 - 08:16 AM, said:

If it will work with 'echo', how do I do it?


Adding Javascript in a PHP page using echo is done like this

<?
echo "<script language=\"Javascript\">\n";
echo "alert("You just used echo to add Javascript");\n";
echo "</script>";
?> 



inside the <script> tags, you would, of course, have your Javascript code not my simple alert message :)

Hope this helps

Happy Coding!



Dear PC
Thanks, it helps but doesn't quite get me there. Could you show me by copying the stuff I put in my original post, into the code you used, so I can see exactly where it goes?

thanks
David


<?php
echo '
<script type="text/javascript"><!--
amzn_cl_tag="exampleID";
//--></script>
<script type="text/javascript" src="http://cls.assoc-amazon.co.uk/gb/s/cls.js"></script>
';
?>



This will do it

This post has been edited by formalsleek: 19 August 2007 - 03:37 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1