WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Ajax WordPress Pagination does not Work (4 posts)

  1. soumyaunknown@gmail.com
    Member
    Posted 1 year ago #

    Hello
    I am looking for : Ajax WordPress Pagination

    I have added below code in index.php

    <ul id='PaginationExample'>
      <li><?php next_posts_link('&laquo; Older Entries') ?></li>
      <li><?php previous_posts_link('Newer Entries &raquo;') ?></li>
      </ul>

    And also added below JS on header.php

    <script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function(){
    jQuery('#PaginationExample a').live('click', function(e){
      e.preventDefault();
      var link = jQuery(this).attr('href');
      jQuery('#contentWrap').html('Loading...');
      jQuery('#contentWrap').load(link+' #content');  
    
      });  
    
      });
      </script><p></p>

    My Index div Structure

    <?php get_header(); ?>
    <div id="contentWrap">
    <div id="content">

    where div#content containing only main Contents (excluding any type of sidebar etc)

    PS: I am new in JQuery

    It seems does not work,page are still loading with Refresh.

    Whats wrong with my code?

    Any Solution?

    Thank you

  2. Hey,

    In your code, you're calling #contentWrap where you should be calling #content

    Ammending your jQuery snippet accordingly would leave it as:

    <script type="text/javascript" charset="utf-8">
    jQuery(document).ready(function(){
    jQuery('#PaginationExample a').live('click', function(e){
      e.preventDefault();
      var link = jQuery(this).attr('href');
      jQuery('#content').html('Loading...');
      jQuery('#content').load(link+' #content');  
    
      });  
    
      });
    </script>

    Additionally, please ensure that this snippet comes after the <?php wp_head(); ?> hook, else jQuery will be loaded after your script and it will not work at all.

    Let me know if this works!

  3. soumyaunknown@gmail.com
    Member
    Posted 1 year ago #

    yes that's my mistake
    forgot to change the target :p

    Thank you

  4. No problem. :)

Topic Closed

This topic has been closed to new replies.

About this Topic