last day (14 days later) » 

9:36 AM
1
Q: jQuery script in Wordpress loop

Matteo PelosiI am trying to loop a jquery script so that it affects all the post loaded. The script has a php variable in it so put it in the loop and thought that this was enough but instead it's only sort of applied only to the first post. Here's my php for the script <?php $valutazione0 = simple_fields_ge...

 
Do you have multiple elements with id=rotator?
 
One in every post loaded but only one in each post
 
An id has to be unique on the whole page. If you use it multiple times you need to generate unique ids. In Wordpress this is commonly done by using id="rotator-<postid>", e.g. id="rotator-16".
 
Thanks, i'm trying this now with -<?php the_ID(); ?>, can i then use rotator-<postid> also in the script?
 
no, <postid> is just a placeholder for the concept. You need to use get_the_id() and echo the id there.
 
9:36 AM
Yep sorry, i noticed later and edited exactly when you replied
alright, i updated te code above with what i have now but it still doesn't work, any clue?
Hello
 
jQuery works a little different in Wordpress ... $ doesn't exist there by default
 
I didn't know of the chat feature
 
try this: jQuery('#rotator-<?php the_ID(); ?>').rotator(
 
should i change it to jQuery
yeah
 
And look in the javascript console of your browser for error messages
 
9:39 AM
Still not working... It displays the rotator on the first post (with a wrong $valutazione0 value) but nothing on the other
console has Uncaught SyntaxError: Unexpected token ,
but i think it's because of another thing i still have to look at
I'm loading posts with ajax
that works but needs to be refined
 
loading posts with ajax could be a problem
 
mm
can you try have a look here
and log in with guest guest
please
 
I don't see a login
 
scriveredicinema.net/wp-admin
when you log in then you can see the full website
the rotator is only on the first post
displays correctly in every single.php
so in you open a post you'll see it next to the title
 
I don't see anything where a rotator could be not working
 
9:47 AM
what do you mean?
 
what I see: ending: ,
on your #rotator-38 the value is missing
this causes the unexpected token
and it could be responsible for javascript not being run afterwards
 
the value is in there because in the single.php rotator is loaded fine
problem is i think
that i get only the first value with simple fields
so now i have a different question
i think i was loading the script wrong
but the problem is in fact here <?php $valutazione0 = simple_fields_get_post_value(get_the_id(), array(3, 1), true);?>
$valutazione0 is what should go after ending:
 
well, I have no idea what you are doing there, I don't know that function
 
alright
thanks tho!
just one more thing
how do you see all the values
?
 

last day (14 days later) »