• Hi,
    I am using the new post thumb in wordpress.
    But I don’t know how to grab the thumb of a page and show it in another page?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I am not sure this is what you were looking for, but it may work. Call this function at the point where you want the thumbnail:

    # Displays post image attachment (sizes: thumbnail, medium, full)
    function dp_attachment_image($postid=0, $size='thumbnail', $attributes='') {
       if ($postid<1) $postid = get_the_ID();
       if ($images = get_children(array(
          'post_parent' => $postid,
          'post_type' => 'attachment',
          'numberposts' => 1,
          'post_mime_type' => 'image',)))
       foreach($images as $image) {
          $attachment=wp_get_attachment_image_src($image->ID, $size);
    ?>< img src="< ?php echo $attachment[0]; ?>" < ?php echo $attributes; ?> />< ?php
    }
    }?>

    See.
    https://codex.www.ads-software.com/Template_Tags/get_the_post_thumbnail

    Supports passing an ID, just feed it the page’s ID instead of a post’s.

    Despite the name, it should in theory work for any post type.

    NOTE: Ultimately, get_the_post_thumbnail calls wp_get_attachment_image, which in turn calls wp_get_attachment_image_src. Either method should work, you might just find the above function a little more convenient.

    Sure – why reinvent the wheel. Thanks for the tip.

    Thread Starter downfast

    (@downfast)

    brilliant thanks. I’ll try it.

    Thread Starter downfast

    (@downfast)

    Hi

    this gives me all the the sub pages of the current page with id6.

    <ul>
    	<?php $pages =
    	$parent = 6;
    	$args=array(
      	'child_of' => $parent
    	);
    	$pages = get_pages($args);
    	if ($pages) {
    	echo get_the_post_thumbnail($page->ID);
      	$pageids = array();
      	foreach ($pages as $page) {
        	$pageids[]= $page->ID;
      	}
        	echo get_the_post_thumbnail($page->ID);
    	wp_list_pages($args);
    	}
    	?>
    </ul>

    How can I do so that I get only 1 random sub page of all the sub pages of page id6?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Use post thumb in any page?’ is closed to new replies.