Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2011, 07:01 PM   PM User | #1
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
jQuery won't work with Wordpress

All,
I have the following bit of code:
Code:
<script type="text/javascript">
$(document).ready(function() {
var url='http://search.twitter.com/search.json?callback=?&q=test';
 	$.getJSON(url,function(json){
		$.each(json.results,function(i,review){
			if(i==1){
			$("#reviews").html('<div id=reviewnum'+i+'><b>'+review.text+'</b><br>Reviewed By: '+review.from_user+'</div>');
			//$("#reviews").append('<div id=reviewnum'+i+'>'+review.text+'</div>');
			}else{
			$("#reviews").append('<div id=reviewnum'+i+'><b>'+review.text+'</b><br>Reviewed By: '+review.from_user+'</div>');
			$("#reviewnum"+i).hide();
			}
		});
	});
});

function rotatereview(){
	var number_id = 2;
	var old_number_id;
	var refreshId = setInterval(function() {
		if(number_id==6){
		old_number_id = number_id - 1;
		$("#reviewnum"+old_number_id).hide("slow");
		number_id = 1;
		$("#reviewnum"+number_id).show("slow");
		}else{
		if(number_id==1){		
      	$("#reviewnum"+number_id).show("slow");
		}else{
		old_number_id = number_id - 1;
		$("#reviewnum"+old_number_id).hide("slow");
		$("#reviewnum"+number_id).show("slow");
		}
		}
		number_id++;
  	 }, 5000);
  	 $.ajaxSetup({ cache: false });
}
rotatereview();
</script>
This code runs at the header or footer (I've tried at both places) of one of my wordpress template pages. The json never gets called to populate the div. I do have the div on my page so it isn't missing but that part works fine.

I looked and wordpress looks like it's trying to load the following jquery:
<script type='text/javascript' src='http://localhost/wordpress/wordpress/wp-includes/js/jquery/jquery.js?ver=1.6.1'></script>

I'm not sure why my jquery won't work with this? Can anyone give me any ideas?

Thanks in advance!
treeleaf20 is offline   Reply With Quote
Old 11-05-2011, 08:41 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Perhaps your code is conflicting with other code already in the page.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-05-2011, 08:45 PM   PM User | #3
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
I'm not sure why, but if I changed $ to jQuery it works good.
treeleaf20 is offline   Reply With Quote
Old 11-06-2011, 09:30 AM   PM User | #4
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,812
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
Here's the explanation:

http://codex.wordpress.org/Function_...flict_wrappers

I always manually add jQuery to the Wordpress header.php to avoid this sort of thing - never had any problems using this approach.
SB65 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:33 PM.


Advertisement
Log in to turn off these ads.