WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

    <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

share|improve this question
Hey Michiel, that's a pretty broad question. If you do some searching you can find a lot of answers that give you a step by step for using ajax in WordPress, which is a little bit different than using it in a straight up app without a framework, although it's pretty much the same thing under the hood. If you have a more specific question, you might get a more detailed answer here. – Andrew Bartel May 26 '13 at 23:16

First, don't use query_posts.


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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.