WordPress.org

Ready to get started?Download WordPress

Forums

Errors after following instructions to include links outside WP (23 posts)

  1. kickass
    Member
    Posted 8 years ago #

    Page in question (toplevel) here:
    http://kickasswebdesign.com/testindex.php

    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:
    http://kickasswebdesign.com/wordpress/

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

    <?php
    require_once("http://kickasswebdesign.com/wordpress/wp-blog-header.php");
    ?>

    (/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-
    <ul>
    <?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?

  2. schulte
    Member
    Posted 8 years ago #

    You'll need to call wp-blog-header.php -- read this rough draft:

    http://codex.wordpress.org/User:Jalenack/Integrating_Wordpress_into_an_Existing_Site

  3. kickass
    Member
    Posted 8 years ago #

    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.

  4. vkaryl
    Member
    Posted 8 years ago #

    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....

  5. schulte
    Member
    Posted 8 years ago #

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

    <?php
    require('/the/path/to/your/wp-blog-header.php');
    ?>

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

  6. vkaryl
    Member
    Posted 8 years ago #

    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....

  7. schulte
    Member
    Posted 8 years ago #

    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.

  8. kickass
    Member
    Posted 8 years ago #

    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?

  9. vkaryl
    Member
    Posted 8 years ago #

    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

    <?php
    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....

  10. schulte
    Member
    Posted 8 years ago #

    Ok, let's simplify this...
    <?php
    /* Short and sweet */
    require('./wp-blog-header.php');
    ?>

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

  11. kickass
    Member
    Posted 8 years ago #

    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!

  12. schulte
    Member
    Posted 8 years ago #

    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?

  13. schulte
    Member
    Posted 8 years ago #

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

  14. kickass
    Member
    Posted 8 years ago #

    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?

  15. schulte
    Member
    Posted 8 years ago #

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

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

    Does that repeat 5 times?

  16. schulte
    Member
    Posted 8 years ago #

    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.

  17. kickass
    Member
    Posted 8 years ago #

    Yup. Oh, and it even copied your misspelling five times! Hello, Word! At least I assume you meant "Hello, World!"

    I should mention also that I put that head call back to require_once just to see if that had something to do with it. It made absolutely no difference.

    That original archive call I used is the exact same one that works fine (and only calls titles once) within my actual blog in either the leftcol or the sidebar, depending on which of my themes you're running. This truly is bizarre. I've damn near got the template tag section of the codex memorized after today.

    Is there a way to do it with a query? I'm not exactly a php whiz, though I can usually follow instructions . . .

  18. When you do this:

    require_once("http://kickasswebdesign.com/wordpress/wp-blog-header.php");

    It get the contents of the OUTPUT of the file, not the actual file contents. This is because you were using a URL instead of a path.

  19. kickass
    Member
    Posted 8 years ago #

    SUCCESS! WOOHOO!

    Just to wrap for anyone who ends up in here on a search- in index.php I have at the very top before the doctype:
    <?php
    require_once("wordpress/wp-blog-header.php");
    define('WP_USE_THEMES', false);
    ?>

    Then, in the place where I want the five most recent titles to show I have:
    <?php wp_get_archives('type=postbypost&limit=5'); ?>

    That was the winning combo that got me my five post titles listed on my site's static index page. YMMV.

    Thank you SO MUCH, schulte, for hanging in there with me!

  20. truenorth
    Member
    Posted 8 years ago #

    kickass -

    Thanks for summing it up! That info was exactly what I was looking for.

  21. gregg28327
    Member
    Posted 8 years ago #

    Is there a way to display the five latest posts in their entirety - as opposed to just the titles - on a static home page?

    I would like to do this ... but have no idea how to. Any help would be greatly appreciated. Thanks.

    Gregg

  22. kickass
    Member
    Posted 8 years ago #

    Gregg, I'm sure there's a way to alter the template tag to do this.

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

    That's the part that would need to be altered. Check in the codex and I'm sure you'll find what you need in the template tags/archives section.

  23. miss-saeki
    Member
    Posted 8 years ago #

    Thanks, this post helped me a lot. Wanted to add that if you want to print the list of recent posts outside WP folder but inside a folder parallel to WP, the initial PHP does need the docroot:

    <?php
    require_once("/home/userid/public_html/otherfolder/wp-blog-header.php");
    define('WP_USE_THEMES', false);
    ?>

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

Topic Closed

This topic has been closed to new replies.

About this Topic