Forums

Placing loop in a different file (2 posts)

  1. raejae
    Member
    Posted 4 years ago #

    I'm making an Ajax-heavy theme, where one of the calls is to update the blog display. In an effort to clean things up, I'm trying to move my loop into a different file that I can call directly.

    I include that file in the original loading of the page:

    <div id="maincontent">
       <?php include(TEMPLATEPATH . '/blog.php'); ?>
    </div>

    but when I call the file directly in my XMLHttpRequest to update the display, it tells me that it can't find the function have_posts(). What else do I need to include to correct this?

  2. Michael Fields
    Theme Wrangler
    Posted 4 years ago #

    This will hypothetically work :)

    1. Create a new file named: blog-ajax.php
    2. Insert the following code into this file:

    require_once '/user/public_html/wp-config.php';
    require_once '/user/public_html/wp-settings.php';
    <div id="maincontent">
       <?php include(TEMPLATEPATH . '/blog.php'); ?>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.