Support » Fixing WordPress » Errors after following instructions to include links outside WP

  • Page in question (toplevel) here:

    I read all the posts and codex articles I could find to include WP stuff in a static html page outside of WP. WP is located here:

    I included this at top of my site’s testindex.php page:


    (/wordpress/wp-blog-header.php” keeps cutting off in the above code when I post, but it is there in the file. I tried a relative url but it would result in page with nothing but an error)

    This is the code to call the last 5 article titles that’s in the rightcol of the layout under the links-
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php wp_get_archives('type=postbypost&limit=5'); ?>
    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>

    <?php endif; ?></ul>

    Obviously it isn’t working. Any suggestions?

Viewing 15 replies - 1 through 15 (of 22 total)
  • You’ll need to call wp-blog-header.php — read this rough draft:

    Um, I did. And I said so in my post, though that’s the snippet of code that the post kept cutting off. But thanks anyway, schulte.

    The OP says the wp-blog-header.php call is in the original file….

    kickass, I had this problem when I was using cg-feedread. Long time back now…. I *think* it had something to do with where exactly I was placing the line that called the file. Let me dig around and see if I (the queen of redundant backups….) might still have the index.php with the call in place. I’ll post back soon as I have a dekko….

    Didn’t realize it got cut off. That undefined function message means its still missing the header.


    Don’t call it using http…use the full path and see what happens.

    Yes, schulte – I think you’ve got it. I did find my setup from ages back – the deal is you need to use “require” instead of “require_once” I believe. I think, from looking at the mishmash of stuff I have available now, that instead of putting it in the header, I had to put it ABOVE the doctype etc. too….

    Hope it works for kickass. You hit on the other key factor — the call needs to be made from the very first line — no whitespace or anything. It has to be first.

    Call originally was made on first line above the doctype with the absolute url. That at least got me a page that looked like mine, though the error showed up in the pullquote box on the right.

    With the relative url, and the call at the very tippytop of the header where it belongs I get a totally white page with this error:

    Warning: main(/wordpress/wp-blog-header.php): failed to open stream: No such file or directory in /home/mywebsite/public_html/testindex.php on line 2

    Warning: main(/wordpress/wp-blog-header.php): failed to open stream: No such file or directory in /home/mywebsite/public_html/testindex.php on line 2

    Fatal error: main(): Failed opening required ‘/wordpress/wp-blog-header.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/mywebsite/public_html/testindex.php on line 2

    I’ve now tried it with the header call both ways- as “require” and as “require_once” — same errors either way.

    Relative path does not work at all- and what’s frustrating is that if you LOOK at the paths in the error message they’re all ‘RIGHT’ in that the files they path to are indeed there. *sigh*

    So, Key Factors notwithstanding, the solutions above have all been tried and don’t work.

    Thanks, guys. Any other ideas?

    Well, I found ANOTHER version of the page setup I was using, a later-dated one as it happens (since none are “in situ” at the moment, I can’t say which was working unfortunately!).

    In this one, I have <?php require('wp-blog-header.php'); ?> as the last line above the </head> tag. Then in the body where I was having the feed (from cg-feedread) display, I have

    call to the feed using FULL hard-coded address to info:
    $feedurl = "http://www. example. com/wp-rss2.php";

    I don’t know if that will help….

    Ok, let’s simplify this…
    /* Short and sweet */

    Now move a copy of the wp-blog-header.php into the same location as testindex.php.

    Okay, including the wp-blog-header.php in the toplevel directory didn’t do it. Weirdly, for some reason I tried a relative url in a different way (“more” relative, instead of from docroot) and got a different error, namely that wp-config wasn’t where it was expected. So I went back and called wordpress/wp-blog-header.php and . . . It worked, kinda. Now I have a different problem. I know I have to restyle here, but take a good look at the list. I have my archive permalink titles repeated- five times. Well at least I feel like I’m getting warmer!

    I see that with a limit of one, it does loop through 5 times. Anything more you can add about your setup?

    Good deal. I think.

    If you change it to limit=1, does that single link repeat 5 times too? I’d guess yes, so you must have some weird loop going on…the Loop used above looks fine; do you have any other fancy stuff going on?

    Yes, if I change it to limit=1, then I have one article title repeating five times. If I totally remove the limit=X then I have every blog title from every blog entry I ever made repeating five times. I’m just trying to list the most recent five article titles once *grin*

    No other fancy stuff going on. FYI this is 1.5 with Markdown, Theme-Switcher, Witty-Text, and WP-ContactForm activated, none of which would seem to have any bearing, at least I wouldn’t think so.

    Just for the record, I tried removing the loop and just having the archive call and was back to whitepage with errors. So yes, the loop is doing the job it’s supposed to do . . . is there another way to call post titles and to limit them to the most recent five?

    Hmmm…what happens if you replace the wp_get_archives call within the Loop with:

    <?php echo 'Hello World!'; ?>

    Does that repeat 5 times?

    I’m an idiot.

    Don’t put the Loop in there. Just throw this in there:

    <?php wp_get_archives('type=postbypost&limit=5'); ?>

    You’ll get your five. Style it anyway you want.

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Errors after following instructions to include links outside WP’ is closed to new replies.