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?
Thank开发者_如何学编程s so much guys, I hope you can help me out.
<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.
Try to change <? echo $id; ?>
to document.URL.split('#?id=')[1]
精彩评论