Displaying Thumbnails (from Custom Fields) on external, non-blog page
-
Hi All…not sure if this has been covered before, but I’m hoping I can find some assistance.
I am currently able to display posts from a specific category on an external, non-blog page. The issue I am having is getting the thumbnail (as specified in the Dashboard, Custom Field section) to display along with the post. Here is the code I am using:
<?php
//db parameters
$db_hostname = ‘XXXX’;
$db_username = ‘XXXX’;
$db_password = ‘XXXX’;
$db_database = ‘XXXX’;//connect to the database
mysql_connect($db_hostname, $db_username, $db_password);
@mysql_select_db($db_database) or die(“Unable to select database”);//get data from database
$query = “SELECT DISTINCT ID, post_title, post_name, guid, post_date, post_content FROM wp_posts as p
INNER JOIN wp_term_relationships AS tr ON
(p.ID = tr.object_id AND
tr.term_taxonomy_id IN (10) )
INNER JOIN wp_term_taxonomy AS tt ON
(tr.term_taxonomy_id = tt.term_taxonomy_id AND
taxonomy = ‘category’)
ORDER BY id DESC LIMIT 5″;$query_result = mysql_query($query);
$num_rows = mysql_numrows($query_result);//close database connection
mysql_close();?>
Next, echoing the content to the page:
<?php
$blog_date = mysql_result($query_result, $i, “post_date”);
$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”);//format date
$blog_date = strtotime($blog_date);
$blog_date = strftime(“Published on %A, %B %e, %G”, $blog_date);//how many characters should be shown?
$maxchars = 200;//strip out the html tags, such as images, etc…
$blog_content = strip_tags($blog_content);//cut down the size of the post to 200 characters
$blog_content = substr($blog_content, 0, $maxchars);
$blog_content = $blog_content . “”;//the following HTML content will be generated on the page as many times as the loop runs. In this case 5.
?>
<?php echo $blog_title; ?>
<?php echo $blog_date; ?>
<?php echo $blog_permalink; ?>The code I am trying to integrate above is: <?php $values = get_post_custom_values(‘thumbnail’); echo $values[0]; ?>
which would ideally echo the thumbnail along with the content. I’ve tried integrating several ways but have not found a solution. Can anyone provide me with some suggestions?Thanks in advance!
- The topic ‘Displaying Thumbnails (from Custom Fields) on external, non-blog page’ is closed to new replies.