Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Francesca_M on "post_id to javascript var"

$
0
0

Hi,
I'm looking for some help:
I need, when the user click on 'read more', to save the post id in a javascript var.

If i use:

<div id="post-<?php the_ID(); ?>">
<script type='text/javascript'>
	<?php
	$num_post="post-".get_the_ID();
	echo "var selected_post='$num_post";
	?>
	</script>

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

the code write the right var for every post, but if I try to use it, I always have the id of the last post of the page. How can I save only the necessary var?


Viewing all articles
Browse latest Browse all 8245

Trending Articles