WordPress.org

Ready to get started?Download WordPress

Forums

Calling a function outside of WP (4 posts)

  1. ibeats
    Member
    Posted 7 years ago #

    http://www.jamesvincent.co.uk/forum/

    i need to call a function from one of my WP hacks. You will see on the left sidebar, that I am trying to get the Recent Posts/Links into the forum sidebar (taken from WP)

    I've tried using:

    <?php /home/jamesv/public_html/wordpress/c2c_get_recent_posts ($num_posts = 10,
    $format = "%post_title%<br>",
    $categories = '',
    $orderby = 'date',
    $order = 'DESC',
    $offset = 5,
    $authors = '',
    $include_passworded_posts = false); ?>

    and tried sticking the above function in a blank page called 'recentposts.php' and including it using:

    <?php include ('/home/jamesvincent/public_html/wordpress/wp-content/themes/vini/sidebar_recent.php'); ?>

    but i get nothing, is this possible? i hope so.

  2. Austin Matzko
    Member
    Posted 7 years ago #

    If you want to use a WordPress function outside of WordPress files, your best bet is to require the WordPress files, like so:

    require('[the path to your WordPress directory]/wp-blog-header.php');

    Note that if you're doing this from within another application, such as forum software or a CMS, you may run into problems where the other app has identically-named functions to WordPress's.

  3. ibeats
    Member
    Posted 7 years ago #

    <?php require ('/home/jamesv/public_html/wordpress/wp-content/plugins/customizable-post-listings.php');?>

    didnt work, when used with:

    <h3>Other Headlines</h3>

    <div class="itemside">

    <?php c2c_get_recent_posts ($num_posts = 10,
    $format = "<a href=\"/?p=%post_id%\">%post_title%</a><br>",
    $categories = '',
    $orderby = 'date',
    $order = 'DESC',
    $offset = 5,
    $authors = '',
    $include_passworded_posts = false); ?>
    </div>

    :sad: :(

  4. Austin Matzko
    Member
    Posted 7 years ago #

    Yeah, you can't just require plugin files. That's why I said you need to require your wp-blog-header.php file.

    Here's what I said to do above, this time with your absolute path spelled out for you:

    require('/home/jamesv/public_html/wordpress/wp-blog-header.php');

Topic Closed

This topic has been closed to new replies.

About this Topic