1

I'm playing With wordpress, loading content into my theme from a custom page. What I have is:

header.php

<script type="text/javascript">
$("#another").click(function(){
   $("#randomPost")
            .text("... loading ...")
            .load("/wp/ajax-page/?id=<? echo $id; ?>+cachebuster=" + Math.floor(Math.random()*10001));
   return false;
});
</script>

index.php

<a href="#?id=1" id="another">Get another!</a>

ajax_page.php (http://localhost/wp/ajax-page/)

<?php
/*
Template Name: AJAX
*/
?>

<?
$id = $_GET['id'];
?>
<?php 
    query_posts('showposts=1&id='.$id.''); 
    the_post();
?>

<a href='<?php the_permalink(); ?>'><?php the_title(); ?></a>

Everything works fine, it's the simpler way that i've found to load data into a div under wordpress (with javascript). My problem is that i can't get to pass the id Var through the URL, any ideas?

Thanks so much guys, I hope you can help me out.

2 Answers 2

1
<script type="text/javascript">
$("#another").click(function(){
   $("#randomPost")
            .text("... loading ...")
            .load("/wp/ajax-page/?id=<?php echo $id; ?>&cachebuster=" + Math.floor(Math.random()*10001));
   return false;
});
</script>

The problem was... on the load. You were printing the $id but you forgot tu add the & so you send the id parameter and the cachebuster parameter. They were together.

Sign up to request clarification or add additional context in comments.

2 Comments

<script type="text/javascript"> $("#another").click(function(){ $("#randomPost") .text("... loading ...") .load("/wp/ajax-page/?cachebuster=" + Math.floor(Math.random()*10001)); return false; }); </script> This works fine!
I forgot. See this article link. Using a function to get the GET parameter instead of printing it on the javascript code. There are a lot of similar functions but that was the first link on google =P
0

Try to change <? echo $id; ?> to document.URL.split('#?id=')[1]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.