#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Question Need to display the latest wordpress post on another site.


    Hello,

    I am creating a new site with php ( not based on wordpress ) and i am also wordpress in it for blogging, i've installed the wordpress in the /blog directory.. I want to display the latest post of wordpress with a short description of it in my front page of the website in the /root directory...

    I want a help fro creating this script.. i dont have much idea of scriting so can any one help me out to make this script...
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Location
    London, UK
    Posts
    3
    Rep Power
    0
    Originally Posted by artinsane
    also wordpress in it for blogging, i've installed the wordpress in the /blog directory
    directory is (largely) irrelevant - as long as you know the access details (host, name, user, password) for the wordpress database, you can simply read the latest post(s) in your main site:

    Code:
    <?php
    
    include_once('/blog/wp-config.php');
    include_once('/blog/wp-includes/wp-db.php');
    
    //parameters
    $db_username = "";
    $db_password = "";
    $db_database = "";
    $db_hostname = "";
    
    //connect to the database
    mysql_connect($db_hostname, $db_username, $db_password);
    @mysql_select_db($db_database) or die("Unable to select database");
    
    $query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' AND post_category='News Flash' ORDER BY id DESC LIMIT 1";
    
    $query_result = mysql_query($query);
    $num_rows = mysql_numrows($query_result);
    
    mysql_close();
    
    $blog_title = mysql_result($query_result, $i, "post_title");
    $blog_content = mysql_result($query_result, $i, "post_content");
    $blog_permalink = mysql_result($query_result, $i, "guid");
    $blog_date = mysql_result($query_result, $i, "post_date");
    
    ?>

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo