WordPress.org

Forums

Solution to display recent posts from blog to website (1 post)

  1. Dubai Web Design - incirclemedia.com
    Member
    Posted 5 months ago #

    <?php
    	$db_username = '#######';
    	$db_password = '#######';
    	$db_database = '#######';  
    
    	$blog_url = 'http://www.#######.com/#######/blog/'; //base folder for the blog. Make SURE there is a slash at the end  
    
    	//connect to the database
    	$con = mysql_connect(localhost, $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' ORDER BY id DESC LIMIT 2";
    
    	$query_result = mysql_query($query);  
    
    	while($row = mysql_fetch_array($query_result))
        {
        ?>
    
        <div class="blog_cont"> <a>"><b><?php echo $row['post_title'] ?></b></a><br clear="all" />
          <span><?php if (strlen($row['post_content']) > 40) { echo substr($row['post_content'], 0, 120) . '...'; } ?></span> <a>">Read More ยป</a> </div>
        <?php }
    	  @mysql_close($con);
    	?>

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 5 months ago by Dubai Web Design - incirclemedia.com
  • This topic is not resolved
  • WordPress version: 3.5