Forums

Displaying Thumbnails (from Custom Fields) on external, non-blog page (6 posts)

  1. tomhubbard28
    Member
    Posted 3 years ago #

    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!

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    Don't you need use the post id using get_post_custom_values?

    Please note I deleted your attempt to kidnap that other topic ;)

  3. tomhubbard28
    Member
    Posted 3 years ago #

    Hi MichaelH

    Thanks for your response...and yes, I was determined to get a response even if it meant holding that other topic ransom! LOL! I apologize...it won't happen again.

    I thought about using the post id. I just couldn't figure out how that would work with what I am trying to accomplish, which is to display the latest posts AND their respective thumbnails on an external, non-blog page.

    Maybe "get_post_custom_values" isn't what I need to accomplish this task after all. Do you know how to achieve this? Anybody????

  4. tomhubbard28
    Member
    Posted 3 years ago #

    Geez, nobody?????? Maybe I should kidnap another topic to get some attention. LOL!

    If somebody could just point me in the right direction of how to display the thumbnail along with it's respective post (blog title, date, and excerpt) on an external, non-blog page...it would be most appreciated.

    Thanks in advance!

    Tom

  5. MichaelH
    Volunteer
    Posted 3 years ago #

  6. mssbee
    Member
    Posted 3 years ago #

    I would like to know how to do that too. Anyone know?

Topic Closed

This topic has been closed to new replies.

About this Topic