Skip to:
Content
Pages
Categories
Search
Top
Bottom

get_the_post_thumbnail & $post_id

  • @malmac

    Participant

    I am currently using the

    get_the_post_thumbnail( $post_id, $size, $attr );

    To create a thumbnail for each topic on my forum index page.
    I would like to be able add the same thumbnail to posts within that topic.
    Can I use $post_id to reference the post topic? Is this a parent/child relationship?

    Something like?
    get_the_post_thumbnail( $topic_thumbnail);

    or
    get_the_topic_thumbnail( $post_id, $size, $attr );

Viewing 5 replies - 1 through 5 (of 5 total)
  • @robin-w

    Moderator

    depends exactly where you are putting that code, and which thumbnail you are wanting

    get_the_post_thumbnail( $reply_id, $size, $attr );

    may well be what you want.

    Otherwise come back with where the code is going.

    @malmac

    Participant

    I am trying to grab the $post_id from the parent
    something like this?

    	function pym_print_featured_image_on_topic() {
    		if (has_post_thumbnail()) {
    			echo '<div class="pym-bbp-topic-thumbnail">';
    			echo get_the_post_thumbnail('post_parent', 'thumbnail' );
    			echo '</div>';
    		}

    @robin-w

    Moderator

    still no clearer on where this code is going, and which thumbnail you are after.. sorry I’d love to help but I’m still not understanding what you are trying to achieve.

    @malmac

    Participant

    Sorry,
    I have a featured image/thumbnail attached to each forum topic.
    I would like each post, in that topic, to call that featured image as well.
    I am assuming that each topic is the parent of each post?

    so I created this function in my functions.php file

    	add_action('bbp_template_before_post', 'pym_print_featured_image_on_topic()')
    	function pym_print_featured_image_on_topic() {	
    			//get the post id of the parent
    			//$postimage = get_post( 'post_parent' );
    		if (has_post_thumbnail()) {
    			echo '<div class="pym-bbp-topic-thumbnail">';
    			echo get_the_post_thumbnail('<strong>post_parent</strong>', 'thumbnail' );
    			echo '</div>';
    		}
    	}

    Which I am then calling in side of loop-single-topic.php

    <?php do_action( ‘bbp_template_before_post’ );?>

    Thanks for your help!

    Malcolm

    @robin-w

    Moderator

    ok – that’s great – I think I now understand

    loop-single-topic is probably not the right/only place

    but within loop single topic, you can get the ID from bbp_topic_id() which will be itself, so no need to call post parent

    Replies – that is posts in response to a topic, which is I think what you are after, are handled by loop-single-reply.php

    There each reply has an id found by using bbp_reply_id, so you would use something like

    $postimage = wp_get_post_parent_id( bbp_reply_id() ); 
    

    in your code above

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar