Passing a varible from jQuery to PHP

I have a a bunch of li’s that are a blog but i want to show them enlarged in a colorbox. Therefore I need to know which li I clicked so I can get that ID and use that in my query to get all the date for that post.

Now I thought that the best way is to retrieve the blog id with jQuery and then use that to add to my query in the footer.

Read More
    <li id="<?php the_ID;?>">blog</li>
    <li id="<?php the_ID;?>">blog</li>
    <li id="<?php the_ID;?>">blog</li>
    <li id="<?php the_ID;?>">blog</li>

    //My colorbox inline frame
    <?php query_posts( 'p="the_ID_of_clicked_li' ); ?>
     etc etc

I think this can be done with AJAX but is there a more simple method and give me a clean URL?

I haven’t AJAX in projects before, so I am a beginner with that.

Any thoughts would be appreciated

Related posts

1 comment

  1. First, don’t use query_posts.

    Second…

    I think this can be done with AJAX but is there a more simple method
    and give me a clean URL?

    PHP runs on the server. Items are “clicked” on the client machine. The only way to pass that “clicked” value back to PHP is via AJAX. Within a WordPress framework that mostly means using the WordPress AJAX API.

    So, there is no more simple method than AJAX to get a “clicked” value back to PHP.

    However, if your original PHP Loop prints the post body to the page and you hide it by default via CSS– ie. display:none— then your jQuery/Javascript can then selectively show/hide content and you don’t need another request to the server at all. That may count as “more simple”, if that is an option.

    I don’t know what “give me a clean URL” means in this context.

Comments are closed.