0

i want to load wordpress posts using ajax on window scroll, it must be similar to facebook loading posts,But i am in stuck with some issue, I have used the code that is loading the posts on window scroll, when i scroll window it shows the posts, but rather showing one by one posts it shows the all posts on single window scroller. Here is the code which i use for this purpose.

Can any one help me to figure out the issue.

Thanks in advance

   <script type="text/javascript">
   jQuery(document).ready(function ($) {
   $(window).scroll(function () {
   var ajaxURL = '<?php echo get_admin_url(); ?>admin-ajax.php';
   var post_id = $('.ajaxclick').attr('id');
        $.ajax({
        url: ajaxURL,
        type: 'POST',
        cache:false,
        beforeSend: function() {
        $("#loading_animation").hide();
        $("#ajaxloader").show();

        },
        complete: function() {
                $("#loading_animation").show();
                $("#ajaxloader").hide();

        },  
        data:   {
                action: 'load_content',
                post_id: post_id,                   
                },
        success: function(response){
        // var i = setInterval( function() {
        // jQuery("#loading_animation").html(response); //Whatever the php page to do the query against here
        // }, 5000 //timeout in miliseconds
            // );

                jQuery("#loading_animation").html(response);
         return false;
                    }   
            });


  });
  });

  </script>
ravinder
  • 15
  • 7
  • change the scroll event from "$(window).`scroll`(function () {...." to load event "$(window).`load`(function() {...." but still i am confused you want Facebook like pagination which lodes more post on scroll event and still in other part of your question you want to lode posts on window load. Basically what do you want? – Abhimanue Tamang Apr 30 '13 at 06:42
  • yes i want to load the posts same as facebook posts – ravinder Apr 30 '13 at 06:45
  • Have you tried searching for questions similar to your problem. Because there are lots of questions similar to yours. – Abhimanue Tamang Apr 30 '13 at 06:48
  • yup i searched regarding this – ravinder Apr 30 '13 at 06:50
  • see Whenever you frame your post always follow 3w rule 1.what did you searched regarding your problem 2.what did you get. and 3. what you want. Ok and hare is something similar to your problem http://stackoverflow.com/questions/3898130/how-to-check-if-a-user-has-scrolled-to-the-bottom – Abhimanue Tamang Apr 30 '13 at 06:52
  • What you want is a Infinite Scroll. Have you tried https://github.com/paulirish/infinite-scroll ? – tbleckert Apr 30 '13 at 06:54

1 Answers1

1

You could check out the fantastic plugin by Paul Irish - Infinite Scroll:

http://www.infinite-scroll.com/

I believe it does exactly what you are looking for.