0

I have tried to make a very simple script for loading pages in wordpress -

<script>
jQuery(document).ready(function(){
 // ajax pagination
 jQuery('.navigation a').live('click', function(){ // wp pagination link on default theme
 var link = jQuery(this).attr('href');
 // #content is the content wrapper
 jQuery('#content').append('<div><h2>Loading...</h2></div>');
 // .entry is a single post wrapper
jQuery('#content').append(link+'.entry')
    });
}); // end ready function
</script>

tried also :

jQuery('#content').load(link+'.entry')

and

//tried also .load.ajax and prepend.ajax
 jQuery('#content').prepend.ajax({
      url: link,
      });

somehow they all work the same, I do see a "loading" div, but then the page gets refreshed with the new posts - I can not seem to append it to the end , or to the div that I need..

2
  • 1
    Do you have separate template to handle the ajax load ?? You cannot directly load and append new pages with normal template. The ajax template shouldn't have header / sidebar / footer and other layout elements. Commented Jun 7, 2012 at 2:28
  • yes , I do have a special template , but it had a header call. stupid me . I will ty to remove, and in the meantie you can post it as an answer for me to accept . Commented Jun 7, 2012 at 4:26

1 Answer 1

1

Your second attempt was correct but if you're targetting an element within the page you're requesting there needs to be a space between the URL and the selector, so instead of this:

jQuery('#content').load(link + '.entry');

Do this:

jQuery('#content').load(link + ' .entry');

That will grab the element .entry and asynchronously load it into #content.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.