1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Integrate wordpress with front page - just want to display the last 10 posts on index.htm

Discussion in 'BlackHat Lounge' started by tony-raymondo, Nov 9, 2009.

  1. tony-raymondo

    tony-raymondo Junior Member

    Joined:
    Jun 19, 2009
    Messages:
    181
    Likes Received:
    459
    So i have a website with a /blog directory

    I want to showcare the last 5 posts from that blog on my front page.

    Anyone ever seen a little php modules / code snippets to place in the index.htm, to do this?
     
  2. kmoore

    kmoore Newbie

    Joined:
    Oct 6, 2009
    Messages:
    42
    Likes Received:
    2
    You can try the following php code that would grab the latest 5 posts directly from your wordpress database.

    Note: This is only a sample code. DB info file, Modifications/Additions required to make it work as intended.

    PHP:
    <?php
    include ('db_info.inc');
    $con mysql_connect($hostname$dbuser$dbpass);
    $select mysql_select_db ($selectdb$con);
    $query "SELECT * FROM wp_posts WHERE post_status = 'publish' ORDER BY ID DESC LIMIT 5";
    $result mysql_query ($query$con);
    $number_rows mysql_num_rows ($result);
    if (
    $number_rows == 0)
    {
    $error_message "No posts yet.";
    echo (
    "$error_message");
    }

    else
    {
    echo (
    "<h2>Last 5 Blog Posts</h2>");
    while (
    $row mysql_fetch_array ($result))
    {
    // construct variables to capture post title, post content and guid (url)
    // You may want to curtail the length of post content
    }

    echo (
    "
    // Format the output using post title, post content and guid variables
    "
    );

    }
    ?>
     
    Last edited: Nov 9, 2009