I am in the process of writing some php to query my wordpress blog database and display the latest post on my homepage which is outside the wordpress environment.
I am not very well-versed in php but i have been able to display the latest blog title, as well as the post content. What I would like to do is have the thumbnail be a clickable link to the post. How do i get the link to the post? I also want to display just the excerpt not the entire post-however using post_excerpt in the same fashion as i have with post_title, post_content, does not seem to work.
// ...Connect to WP database
$dbc = mysql_connect(XXX,XXX,XXX);
if ( !$dbc ) {
die( 'Not Connected: ' . mysql_error());
}
// Select the database
$db = mysql_select_db('wrd_2ikhd5ho53');
if (!$db) {
echo "There is no database: " . $db;
}
// ...Formulate the query
$query = "
SELECT post_title,post_content,UNIX_TIMESTAMP(post_date) AS post_date_unix, ID
FROM `wp_posts`
WHERE `post_status` = 'publish'
AND `post_password` = ' '
AND `post_type` = 'post'
ORDER BY `wp_posts`.`post_date` DESC
";
// ...Perform the query
$result = mysql_query( $query );
// ...Check results of the query and terminate the script if invalid results
if ( !$result ) {
$message = '<p>Invalid query.</p>' . "\n";
$message .= '<p>Whole query: ' . $query ."</p> \n";
die ( $message );
}
// Init a variable for the number of rows of results
$num_rows = mysql_num_rows( $result );
$row = mysql_fetch_array( $result, MYSQL_ASSOC );
// Init var for DATE of the post
$post_date = date( "l, F jS, Y ", $row['post_date_unix'] );
// Init var for TITLE of the post
$post_title = $row['post_title'];
// Init var for CONTENT of the post
$post_content = $row['post_content'];
$post_excerpt = $row['post_excerpt'];
// Init var for Excerpt of the post
// Print the number of posts
echo "$post_title";
echo "$post_date";
// Free the resources associated with the result set
if ( $result ) {
mysql_free_result( $result );
mysql_close();
}
?>
the website to reference is http://www.uniconutrition.com
Thanks guys