Retrieve wordpress recent posts from external website

Advert test
#1
Hello All, just looking for recommendations on which is the best way to parse the recent posts of a wordpress blog onto another non blog website?
 

mneylon

Administrator
Staff member
#2
Simplest solution would be to use RSS.

There's plenty of ways of doing it. If you're lazy you could use feedburner, like I'm doing on Michele J. Neylon :: Web ramblings and more..

OR you could use one of the many RSS libraries like Carp etc., etc.

Up to you really :)

Of course if you were using MovableType you could simply use a widget :)
 

Forbairt

Portfolio Building
#7
if you just want to pull the posts ... and so on ...

about 15 minutes to half an hour

to actually write the bit of code probably a minute ... to format it nicely and so on ... probably the rest of the time ...
 
#9
there is something I use myself
PHP:
$show_blog = true;
if($show_blog){
//replace HOST, USER, PASS, DB_NAME with your DB details
$limit = 10;
 $con = mysql_connect(HOST,USER,PASS);
 if (!$con){ die('Could not connect: '); }
 // make foo the current db
 $db_selected = mysql_select_db('DB_NAME', $con);
 if (!$db_selected) {
  die ('Can\'t use db : ');
 }
 echo "<div class='left_tab'>Recent Posts...</div>
  <div class='left_menu'>
  <ul>";
 $sSql = "SELECT `ID`,`post_title`, `wp_posts`.`guid` FROM `wp_posts` WHERE `wp_posts`.`post_status` =  'publish' 
 AND `wp_posts`.`post_type` =  'post' ORDER BY `wp_posts`.`post_date` DESC LIMIT 0, $limit"; 
 $rs_blog = mysql_query($sSql,$con) or die("no connection");
 while($row_blog = mysql_fetch_array($rs_blog)){
  echo "<li><a href='".$row_blog['guid']."' title='".
  htmlspecialchars(str_replace("'"," ",$row_blog['post_title']))."' target='_blank'>&bull; ".htmlspecialchars($row_blog['post_title'])."</a></li>"; 
 }
 mysql_free_result($rs_blog); 
 echo "</ul>
 </div>";
 mysql_close($con);
}
 
#12
Louie,

Thanks a lot for the code snippet. I know a bit of PHP. Question: Will my db password be safe from prying eyes if I input it in this piece of code?
 
Top