Everytime I enter a posts page, index.php is called. Now on the site I load next pages (page2, page3...) with Ajax and insert the posts (just the posts) from the Ajax result inside my page. This works perfect but I was wondering if it is possible to have a different page template for second-pages so I would just load the articles in those (no scripts or styles or parent-innecesary divs).

This way the Ajax call would be faster.

A thing to consider is that if it would be possible, it wount just be for the page number different to one, as the user might enter directly in the fourth page (this one should have all the styles and divs) and then load the fifth, sixth by this second-Ajax template.


I realized about https://stackoverflow.com/questions/3124636/detect-ajax-calling-url

if (strcasecmp('XMLHttpRequest', $_SERVER['HTTP_X_REQUESTED_WITH']) === 0)


<?php get_header(); ?>

    <div id="main">

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

        <article id="post-<?php the_ID(); ?>">



    <?php endif; ?>


<?php get_footer(); ?>

And then I load via javascript Ajax next pages:


    url : page_to_load,

    success : function (data) {

        $('#main').append($('#main>article', data));



If Im right, every time an Ajax page is called all the page is actually downloaded (scripts,etc.)

I was sondering if it would be possible to have a different page template for this second page, something like:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

        <article id="post-<?php the_ID(); ?>">



    <?php endif; ?>

So ONLY articles are loaded, no header,scripts,styles or anything extra.


  • 2
    Please post actual, relevant code. – Chip Bennett Oct 22 '13 at 20:36
  • see this answer – Milo Oct 23 '13 at 15:29
  • Thanks for the link, I have to check it slowly, a lot information. – Alvaro Oct 24 '13 at 18:09
  • Just if anyone is interested, I found this tutorial on the subject : code.tutsplus.com/articles/… – Alvaro Mar 3 '14 at 8:46

Browse other questions tagged or ask your own question.