Title: Using The Loop on external page
Last modified: August 18, 2016

---

# Using The Loop on external page

 *  [ctw](https://wordpress.org/support/users/ctw/)
 * (@ctw)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/)
 * I have a wordpress blog installed at [http://www.domainname.com/blog](http://www.domainname.com/blog).
   And I want recent post headlines, and an excerpt to show on the main page of 
   my site, outside of that blog directory. I’m trying to use The Loop, but it doesn’t
   seem to understand it outside of the blog itself.
 * Can The Loop be used outside of the blog directory? Is there a way I can tell
   the main page, or any page for that matter, where to look so it can understand
   the functions and variables used inside The Loop. I see plenty of sites out there
   showing blog posts on their main page, but I can’t figure out how they’re doing
   it.
 * The error I’m getting right now on my page is “Fatal error: Call to undefined
   function have_posts() in /var/www/html/domainname.com/www-dev/index.php on line
   299”
 * Can somebody please send me in the right direction. My last post was completely
   ignored.
 * Thank you, Thank you

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/#post-604335)
 * If your “main page” is a .php file, you can make it WP-aware in this way:
    add
   at the very top of the file, before everything:
 *     ```
       <?php
       require('./blog/wp-blog-header.php');
       ?>
       ```
   
 * and after that you can use any WP function in that file. (make sure the path 
   to your blog install is correct in the code above!)
 *  Thread Starter [ctw](https://wordpress.org/support/users/ctw/)
 * (@ctw)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/#post-604343)
 * so do you mean it would have to be:
 * <?php
    require(‘[http://www.domainname.com/blog/wp-blog-header.php&#8217](http://www.domainname.com/blog/wp-blog-header.php&#8217););?
   >
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/#post-604346)
 * NO!
    That’s an URI. I said **path**. Meaning server path. If your WP is installed
   in a subfolder called “blog” – then the code I have given above should be used
   without any change!
 *  Thread Starter [ctw](https://wordpress.org/support/users/ctw/)
 * (@ctw)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/#post-604356)
 * That’s awesome! I can’t believe it turned out to be something so simple. Thank
   you so much for the help!
 *  [michaeljdennis](https://wordpress.org/support/users/michaeljdennis/)
 * (@michaeljdennis)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/#post-604521)
 * Awesome guy. Worked perfectly. One question. How can I make it display **only
   the most recent post**? I want my home page to display only the most recent post.
   Then on the blog page it will show all posts. Thanks!
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/#post-604522)
 * Since the title is “using [The_Loop](http://codex.wordpress.org/The_Loop)” I 
   am assuming that’s what you are doing… Use the [query_posts](http://codex.wordpress.org/Template_Tags/query_posts)
   before the Loop, set to show 1 post.
 * Alternatively, you may consider:
    a) using your RSS feeds and magpie b) using
   a recent posts plugin

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Using The Loop on external page’ is closed to new replies.

## Tags

 * [display](https://wordpress.org/support/topic-tag/display/)
 * [external](https://wordpress.org/support/topic-tag/external/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [moshu](https://wordpress.org/support/users/moshu/)
 * Last activity: [18 years, 7 months ago](https://wordpress.org/support/topic/using-the-loop-on-external-page/#post-604522)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
