WordPress: Get URL Only of Featured Image

Terakhir diperbaharui: Kamis, 25 Agustus 2016 pukul 15:12
Tautan: http://darto.id/c

Untuk menampilkan featured image di WordPress sangat mudah sekali, cukup dengan perintah:

<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>

Contoh:

<?php echo get_the_post_thumbnail( $post->ID, full, array( 'style' => 'margin-bottom: 15px;' ) ); ?>

Dan option sizenya bisa disesuaikan dengan keinginan kita, thumbnail, medium, large dan full atau dengan ukuran yang bisa kita custom sendiri, misal array( 100, 100).

Tapi, bagaimana kalau kita hanya menginginkan URL imagenya saja tanpa ada ukuran? Kadang hal ini kita butuhkan dengan tujuan untuk responsive display di website atau email template.

Ternyata ada function bawaan dari WordPress yang bisa kita gunakan untuk hal ini, yaitu mendapatkan URL dari featured image dan juga titlenya. Berikut kodenya:

$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_object = get_post($thumbnail_id);

Cara menggunakannya adalah:

<img src="<?php $thumbnail_object->guid; ?>" style="height:auto !important; max-width:600px !important; width: 100% !important;" alt="<?php $thumbnail_object->post_title; ?>">

Okay, semoga bermanfaat :D. Bagi yang ngerti itu juga, hehehehe.

WordPress: Featured Image URL

Terakhir diperbaharui: Kamis, 25 Agustus 2016 pukul 15:12
Tautan: http://darto.id/1a

Post thumbnails are pretty useful and pretty easy to use in WordPress. Simply add:

add_theme_support('post-thumbnails');

To a theme’s functions.php file and you’ll get a Featured Image module on the admin screen for posts which allows you to select one.

It is also very easy to output that image as an HTML <img>:

the_post_thumbnail();

But what if you just need the URL? Say, you’re going to use it as a background-image on an element rather than a content image. Unfortunately there is no super easy/obvious function for that.

Within the loop, you’ll have to do:

$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];

Then $thumb_url will be that URL.

source: CSS tricks

WordPress: Featured Image Thumbnail in Posts or Pages Admin [update]

Terakhir diperbaharui: Senin, 25 September 2017 pukul 16:20
Tautan: http://darto.id/1d

Last year I post about How to add featured image thumbnail to WordPress admin columns and the code seems not right, because the result give a full resolution of Featured Image, and that’s is so messy.

And here I tried to update the code. Well, actually not update, instead replace the code with the new one :D.

Write the code below in your functions.php

if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {
	
	// for post and page
	add_theme_support('post-thumbnails', array( 'post', 'page' ) );
	
	function fb_AddThumbColumn($cols) {
		
		$cols['thumbnail'] = __('Thumbnail');
		
		return $cols;
	}
	
	function fb_AddThumbValue($column_name, $post_id) {
			
			$width = (int) 35;
			$height = (int) 35;
			
			if ( 'thumbnail' == $column_name ) {
				// thumbnail of WP 2.9
				$thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
				// image from gallery
				$attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
				if ($thumbnail_id)
					$thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
				elseif ($attachments) {
					foreach ( $attachments as $attachment_id => $attachment ) {
						$thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
					}
				}
					if ( isset($thumb) && $thumb ) {
						echo $thumb;
					} else {
						echo __('None');
					}
			}
	}
	
	// for posts
	add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
	add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );
	
	// for pages
	add_filter( 'manage_pages_columns', 'fb_AddThumbColumn' );
	add_action( 'manage_pages_custom_column', 'fb_AddThumbValue', 10, 2 );
}

Change the width and height in the line 15 and 16 for your best preview.

source: wpengineer

Skreenics – Video Contact Sheet Generator

Skreenics is a Mac OS X application that is designed to easily create thumbnails from your videos. You simply drag ‘n drop files and folders onto the main screen, and Skreenics will generate the thumbnails the way you asked it!.

Skreenics is the right tool for Video Contact Sheet generator that run on mac.

Download Mirror

 

How to add featured image thumbnail to WordPress admin columns

Terakhir diperbaharui: Kamis, 25 Agustus 2016 pukul 15:12
Tautan: http://darto.id/6i

The admin pages listing the site’s posts and pages come with various text columns like title, tags, categories, author and so on. In order to see what the featured images are, you have to visit each post or page individually. Using this hack you can add a column with a reasonably sized thumbnail copy of the featured image. Please note that this only works for themes that support featured images.

Just add following code to your theme’s functions.php file.

// Add the posts and pages columns filter. They can both use the same function.
add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
add_filter('manage_pages_columns', 'tcb_add_post_thumbnail_column', 5);

// Add the column
function tcb_add_post_thumbnail_column($cols){
  $cols['tcb_post_thumb'] = __('Featured');
  return $cols;
}

// Hook into the posts an pages column managing. Sharing function callback again.
add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);

// Grab featured-thumbnail size post thumbnail and display it.
function tcb_display_post_thumbnail_column($col, $id){
  switch($col){
    case 'tcb_post_thumb':
      if( function_exists('the_post_thumbnail') )
        echo the_post_thumbnail( 'admin-list-thumb' );
      else
        echo 'Not supported in theme';
      break;
  }
}

Source: http://j.mp/15q4vaH