WordPress.org

Ready to get started?Download WordPress

Forums

including wp-blog-header.php in external php file (13 posts)

  1. phillipcc
    Member
    Posted 7 years ago #

    To gain access from external files to the wordpress functions I just need to include the wp-blog-header.php in the external file. Right?

    Example:
    http://site/wordpress/
    http://site/index.php <--include ./blog/wp-blog-header.php

    So far so good. Second example, including the wp-blog-header.php as the following situation:
    http://site/wordpress/
    http://site/another/index.php <--include ../blog/wp-blog-header.php

    Now permalinks turned on.

    Ok, then I did a few tests with lynx:
    lynx http://site/ returns 200
    lynx http://site/index.php returns 200
    lynx http://site/another/index.php returns 200
    lynx http://site/another/ returns 404 but page displays

    Something is wrong with the last test, but what? Notice if I turn permalinks off all tests return 200.

    Help!

  2. peiqinglong
    Member
    Posted 7 years ago #

    Actually it's the wp-config.php file.

  3. phillipcc
    Member
    Posted 7 years ago #

    What do you mean by that?

  4. peiqinglong
    Member
    Posted 7 years ago #

    If you want to use wordpress functions in another PHP program, you need to do a <? php include_once(path/to/wordpress/wp-config.php) ?> that will load wordpress functions into whatever php program you want to use wordpress in. wp-blog-header.php is something else.

  5. moshu
    Member
    Posted 7 years ago #

    Hmm... every Codex article and hundreds of forum topics always say to use wp-blog-header.

  6. whooami
    Member
    Posted 7 years ago #

    @peiqinglong,

    uh no. You are absolutely wrong.

    the proper way to do it is to include wp-blog-header.php

    For instance, if the page you are trying to do this on resides in the same directory, you use:

    <?php
    /* Don't remove this line. */
    require('./wp-blog-header.php');
    ?>

    rather than share the source of all the files Ive done this in .. ill just suggest you do some reading:

    http://wordpress.org/support/topic/96768?replies=5
    http://wordpress.org/support/topic/117418?replies=14
    http://wordpress.org/support/topic/86399?replies=41

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


    Grab the header:

    In order to transform regular PHP pages into ones that utilize WordPress, you need to add either of the following code snippets to the start of each page.

    <?php
    /* Short and sweet */
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
    ?>
    <?php
    require('/the/path/to/your/wp-blog-header.php');
    ?>

  7. whooami
    Member
    Posted 7 years ago #

    I will kill the dying horse by posting the content of wp-blog-header.php, the contents of which explain precisely why its the file that needs to be called:

    <?php
    if (! isset($wp_did_header)):
    if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) {
    	if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = '';
    	else $path = 'wp-admin/';
    require_once( dirname(__FILE__) . '/wp-includes/classes.php');
    require_once( dirname(__FILE__) . '/wp-includes/functions.php');
    require_once( dirname(__FILE__) . '/wp-includes/plugin.php');
    wp_die("There doesn't seem to be a <code>wp-config.php</code> file.
    I need this before we can get started. Need more help? <a href='http://codex.wordpress.org/Editing_wp-config.php'>We got it</a>.
    You can <a href='{$path}setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file.", "WordPress &rsaquo; Error");
    }
    $wp_did_header = true;
    require_once( dirname(__FILE__) . '/wp-config.php');
    wp();
    gzip_compression();
    require_once(ABSPATH . WPINC . '/template-loader.php');
    endif;
    ?>

    Notice that in addition to to the other files, it loads the config file. It always has.

  8. peiqinglong
    Member
    Posted 7 years ago #

    I'm sorry everyone, I stand corrected. I was thinking of something completely different.

  9. whooami
    Member
    Posted 7 years ago #

    no worries :)

    I kill dying horses, daily.

  10. jeremys
    Member
    Posted 6 years ago #

    I am getting this problem on my blog. Does anyone know what is going on?!

    Warning: main(/home/yahphoto/public_html/designerhacks/wp-admin/wp-includes/classes.php): failed to open stream: No such file or directory in /home/yahphoto/public_html/designerhacks/wp-admin/wp-blog-header.php on line 8

    Fatal error: main(): Failed opening required '/home/yahphoto/public_html/designerhacks/wp-admin/wp-includes/classes.php' (include_path='.:/usr/local/lib/php') in /home/yahphoto/public_html/designerhacks/wp-admin/wp-blog-header.php on line 8

  11. Shivanand The Designer
    Member
    Posted 6 years ago #

    ya. you must be missing the dot before the slash i.e. using "/mydirectory/" instead of "./mydirectory/"

  12. boruschek
    Member
    Posted 6 years ago #

    I've got exactly the same problem like phillipcc

    lynx http://site/ returns 200
    lynx http://site/index.php returns 200
    lynx http://site/another/index.php returns 200
    lynx http://site/another/ returns 404 but page displays

    Something is wrong with the last test, but what? Notice if I turn permalinks off all tests return 200.

    Is there a solution???
    Cheers
    Jo

  13. sciencebase
    Member
    Posted 6 years ago #

    Hahahah, the image of you killing some poor old dying horse...not nice. I think the phrase you were after is "flogging a dead horse". I.e. doing something totally pointless as in whipping a deceased equine.

    db

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.