• andy14

    (@andy14)


    Is it possible to call a WordPress function on a page that has nothing to do with WordPress?

    For example: I have a PHP document on my server that acts simply as a page of content. Let’s just say it’s called randompage.php. This page has nothing to do with my WordPress installation and is located in a completely different directory.

    I obviously can’t just write <?php bloginfo(‘name’); ?> on that page. Is it possible to somehow put some code before the <? php bloginfo(‘name’); ?> to basically say “get this information from my WordPress installation”.

    I don’t want to include any other info (such as the theme or header info), just simply the blog title.

    Hopefully that makes sense!

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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).

    scooby

    (@scooby)

    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.

    scooby

    (@scooby)

    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.

    wooooo thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WP function on php page’ is closed to new replies.