The wp-config file is not only a simple connect file, but the gateway to all the WordPress functions.
Try this:
<?php
include "[PathToYourBlog]/wp-config.php";
bloginfo('name');
?>
Thread Starter
andy14
(@andy14)
That works a charm on a regular PHP page of text. However, it breaks when the page I’m calling it on belongs to another script.
I’m trying to display the blog name (and, ultimately, some other wp functions) on a page called displayimage.php which belongs to a another script called Coppermine gallery. Unfortunately, when I visit the displayimage.php page I get an error “Call to a member function on a non-object in “path/wp-includes/functions.php”.
I’m no programmer, but I’m guessing it’s something to do with the WP config file clashing with the Coppermine files/functions. I’m not sure if it is possible, but is there someway to say “connect to the wp config file, pull the blog name, and then stop any connection to wordpress”?
The code I’m currently using to display the name is:
<?php include "/full/path/to/file/wp-config.php"; wp_title(' '); ?>
Works fine on a regular non-WP page, through breaks when used on another PHP script (Coppermine).
Try this bit of code out from the main index page of wordpress:
<?php
define('WP_USE_THEMES', true);
require('./wp-blog-header.php');
?>
But instead of having it set to “true”, set it to “false”. This seems to stop the default wordpress theme from overriding your existing theme.. Also, make sure you put the right path to your wp-blog-header.php file..
For example my file is located here:
require('./blog/wp-blog-header.php');
That worked just perfectly for me.. Took forever to figure those simple changes out, but I’m lovin it now!
Hope that’s what you were looking for..
Thread Starter
andy14
(@andy14)
Thanks for the help Scooby!
That code works, too, on just a normal page which isn’t part of the WP installation.
That code is:
<?php
define('WP_USE_THEMES', false);
require('/path/wp-blog-header.php');
wp_title(' ');
?>
However, I get the same error when using that code in another script (Coppermine gallery). Perhaps it’s not possible due to the scripts somehow clashing.
I’m ultimately trying to include the latest 5 posts from WP on my Coppermine gallery script. I’m just using wp_title as a really basic example to make sure I can include info from WP on another page. Again, it works fine on a regular page outside the WP installation, but not in the Coppermine script.
The path is correct, too.
Yeah I think that’s all your problem is then.. I hate when that happens..
Thread Starter
andy14
(@andy14)
Maybe so 🙁 I want to include the five latest posts in my header file which is dynamically included on every page of my site, including my WP template. The code above works on every page except the gallery pages, which also include the header file.