Support » Fixing WordPress » Using The Loop on external page

  • I have a wordpress blog installed at 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)
  • 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!)

    so do you mean it would have to be:

    <?php
    require(‘http://www.domainname.com/blog/wp-blog-header.php’);
    ?>

    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!

    That’s awesome! I can’t believe it turned out to be something so simple. Thank you so much for the help!

    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!

    Since the title is “using The_Loop” I am assuming that’s what you are doing… Use the 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.