Displaying custom field outside the loop.

Discussion in 'PHP' started by MafiaPenguin, Sep 27, 2011.

  1. #1
    Hi people,

    I'm trying to display a custom field (outside of the loop of the post it belongs too) on a different page. What i'm trying to achieve is a list of posts with a thumbnail next to them. If you could help me out here, i'm not sure about php when it comes to this level. Thanks!

    Here is what i have so far...

    <?php
            $args = array( 'numberposts' => '10' );
    	$recent_posts = wp_get_recent_posts( $args );
            foreach( $recent_posts as $recent ){
            	echo '<div class="construct-filmlistbox"><div class="construct-filmlistthumbnail"></div><li><a href="'.  get_permalink($recent["ID"])  . '" title="Look '.$recent["post_title"].'" >' .  $recent["post_title"].'</a></li></div> ';
        }
    ?>
    PHP:
    I found some code on a site for implementing custom fields outside the loop but i can't figure out how to use it there. Im trying to display inside the div tag 'filmlistthumbnail'

    Heres the code...

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'Your-Custom-Field', true);
    wp_reset_query();
    ?>
    PHP:
    And here's the link to my website. This section of code is for the bottom left of the page, The list of posts. http://www.filmhammer.com

    Thanks :)
     
    MafiaPenguin, Sep 27, 2011 IP