WordPress.org

Ready to get started?Download WordPress

Forums

Placing latest post on non-wp index.php (3 posts)

  1. mtndank
    Member
    Posted 8 years ago #

    Hi, I am developing a site where we have a /wordpress directory and would like to display the latest blog post on the /index.php home page, which is not in the wp directory. Any help or advice would be appreciated.

    Thanks,
    Dan

  2. cron
    Member
    Posted 8 years ago #

    Here is some slightly modified code from a chaitgear plugin


    <?phprequire('yourthinghere/wp-blog-header.php');$comment_author = htmlspecialchars(stripslashes(trim($_GET['author'])));$page = intval($_GET['page']);function get_recentposts($limit = 5) { global $wpdb, $post; $recentposts = $wpdb->get_results("SELECT $wpdb->posts.ID as post_id, post_title, post_name, post_date, user_nickname FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->posts.post_author WHERE post_date_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' AND post_password = '' ORDER BY post_date DESC LIMIT $limit"); foreach ($recentposts as $post) { $post_title = htmlspecialchars(stripslashes($post->post_title)); $post_date = mysql2date('d.m.Y', $post->post_date); $user_nickname = htmlspecialchars(stripslashes($post->user_nickname)); echo "
    <li><a>$post_title</a></li>
    "; }}?><?phpif(empty($comment_author)) {?>
    <ul><?php get_recentposts(); ?></ul> <?php}?>

    Just change the 'yourthinghere/wp-blog-header.php' to the location of your wp-blog-header.php (the "yourthinghere" will be the directory where wordpress is installed.

    If you are using your own plugin to display the last posts then just include a <?php include('yourthinghere/wp-blog-header.php'); ?> before you make a call to the plugin.

    I hope that helps.

    Cron

  3. mtndank
    Member
    Posted 8 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic