0

Im loading post into a content area via ajax but the latest post is the only one that loads, any one encounter this and manage to fixed it, if so please enlighten me.

   <div class="content">    

<?php $args = array('posts_per_page' => 1); query_posts($args);?>
<?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>



      <div class="clear"></div>

      <?php endwhile; ?>
       <?php wp_reset_query(); ?>

    </div>

its not my ajax script because I get the same result every time, and yes single.php is present but im not using it in anyway.

The javascript

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 + " #inner"; 

            $mainContent.slideUp('slow').load(url, function() {
                $mainContent.slideDown('slow');
            });
        });


    jQuery(window).trigger('hashchange');

The links to load for ajax

<!--Slide -->
            <div id="slider" class="clearfix">

                  <ul id="roundabout" class="clearfix">

                        <?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>

                    <a id="left" href="#">Left</a>
                    <a id="right" href="#">Right</a>

            </div>
        <!-- End #slider -->
  • How are you using ajax, could you post your code please? From the above you are querying for the last post and then displaying it. – Stephen Harris Feb 25 '12 at 17:50
  • that could be the problem, how would i know if I am. – John Doe Feb 25 '12 at 19:06
1

OK, so you're not using AJAX (you didn't share any Javascript here, so I may be confused as to what I'm looking at) but this line:

<?php $args = array('posts_per_page' => 1); query_posts($args);?>

indicates you are setting the number of posts to be displayed to just 1, hence the "posts_per_page" value being set to 1. To increase the number of posts display, push that number up to 10 or 20 or whatever you need.

  • I only want one post to show at a time, Its a one page website with load post link from a carousel. – John Doe Feb 25 '12 at 18:34
  • I manage to fix it thanks chris. I change the dashboard reading setting post per page to 1, and removed query post from the main loop. :) – John Doe Feb 26 '12 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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