Get Posts from Wordpress to an External Page
Below will get the All articles from Wordpress Database to an external file and display in random order.Also, it depends on how you customized your “Permalink Structure”. Sample below has “/article/%postname%/%post_id%/”. I am using the same code on my footer!
//////////////////////////////////////////////////////////////////////
$conn = mysql_connect('localhost','root','');
mysql_select_db("keithics",$conn) or die(mysql_error());
if (!$conn) {
die('Error!!--> ' . mysql_error()); // if there's an error, e.g. wrong password or username.
}
$sql = "Select * from `wp_posts` where post_status = 'publish' order by rand() limit 5 ";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo '<a href="'.$site.'blog/article/'.$row['post_name'].'/'.$row['ID'].'/">'.$row['post_title'].'</a>';
}
Related posts:
- Get Articles from a specific cagetory in Wordpress After googling and not found any code, I made my...
- Wordpress get_page() function Well this is the first time that I am having...
Tags: Freelancing, PHP programming, Wordpress
November 27th, 2008 at 6:44 am
Yes I agree with you!