OK here goes, I’m using jQuery ajax to load post from inside a slider. In wordpress dashboard I set the number of post per page to “one”.
The problem I’m having is only the latest post created keeps on being loaded. Also sometimes the inner loop keep on going forever.
I need whatever link from the slider, when clicked, to simply load the post inside the content area I set, Below is all the relevant code.
The slider code
<ul id="roundabout" class="clearfix">
<?php $argss = array(
"showposts" =>20);
query_posts($argss); ?>
<?php while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink();?>"><?php the_post_thumbnail(array(150, 150, true));?></a></li>
<?php endwhile; ?>
</ul>
The jQuery ajax code
var $mainContent = jQuery(".content"),
siteUrl = "http://" + top.location.host.toString(),
url = '';
jQuery(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-login.php]):not([href$=/feed/])", "click", function() {
location.hash = this.pathname;
return false;
});
jQuery(window).bind('hashchange', function(){
url = window.location.hash.substring(1);
if (!url) {
return;
}
url = url + " .content";
$mainContent.fadeOut().load(url, function() {
$mainContent.fadeIn();
});
});
jQuery(window).trigger('hashchange');
The PHP code
<?php while ( have_posts() ): the_post(); ?>
<div class="content">
<?php wp_reset_query(); ?>
<?php while(have_posts()): the_post(); ?>
<div id="inner">
<h2 class="title"><?php the_title(); ?></h2>
<?php the_post_thumbnail(array(150, 150, true)); ?>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="clear"></div>
</div>
<?php endwhile; ?>
take a look at WP_Query in the codex: http://codex.wordpress.org/Class_Reference/WP_Query
Your ‘loop inside a loop’ wont work as you’ve structured here because there is no second query. Try using WP_Query inside the first main loop to get the posts for your second loop
This should help solve half of your problem 🙂