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

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

    Thread Starter ibeats

    (@ibeats)

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

    🙁 🙁

    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');

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Calling a function outside of WP’ is closed to new replies.