Thumbnail The List Post
you use the theme on your network have never seen in the Post management representative thumbnail images in it?
At first I used the theme on the net I happened to see the picture, after groping do this. You can do it no more than 3 minutes from the time you read this line, but you let me track my code how it works offline.
You copy all the code and paste it into your function.php file offline.
// thêm cột để chứa anhrcho cả post và page
add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
// hàm để thêm cột
function tcb_add_post_thumbnail_column($cols){
$cols['tcb_post_thumb'] = __('Featured');
return $cols;
}
// gọi lại hàm để tạo ảnh
add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
// hàm thêm ảnh vào trong list post và list page
function tcb_display_post_thumbnail_column($col, $id){
switch($col){
case 'tcb_post_thumb':
if( function_exists('the_post_thumbnail') )
echo the_post_thumbnail( array(60,60) );
else
echo 'Not supported in theme';
break;
}
}
finished you copy and paste, right? wordpress code so simple right? copy and paste is my criteria for you, then contemplate the following code. Too easy, o la la …
first learn about the top two lines of the function call offline
add_filter('manage_posts_columns', 'tcb_add_post_thumbnail_column', 5);
if you do not know “add_filter” is what the hell is the time to view them, which parameter “manage_posts_columns” is to manipulate parameters in the column in wordpress. “Tcb_add_post_thumbnail_column” column is the additional function declared below the maxillary second
function tcb_add_post_thumbnail_column($cols){
$cols['tcb_post_thumb'] = __('Featured');
return $cols;
}
You replace the word “Featured” in words that you like, such as “Avatar,” for example.
First communication function parameters “$ cols” parameter of wordpress, you write the correct parameter name, which contain information about the column, the list in the post. The second row is declare column named “Featued” the. This article is similar to my previous post about showing the number of attachments in the list post, if you do not see if you can see here
add_action('manage_posts_custom_column', 'tcb_display_post_thumbnail_column', 5, 2);
function on modules to perform functions “tcb_display_post_thumbnail_column”
function tcb_display_post_thumbnail_column($col, $id){
switch($col){
case 'tcb_post_thumb':
if( function_exists('the_post_thumbnail') )
echo the_post_thumbnail( array(60,60) );
else
echo 'Not supported in theme';
break;
}
}
two functions used to create thumbnail size 60.60, you can change as you like. First, it will take on the parameter “$ col”, it will deal with columns named “tcb_post_thumb” (declared in the function “tcb_display_post_thumbnail_column”).
Following eligibility see this theme to function declaration creates a thumbnail, if not you add this line to the file function.php always okay. Without this function declaration tahy for the picture, it will display text “Not supported in themes”.
add_theme_support('post-thumbnails');
if the posts thumbnail, it will run command line “the_post_thumbnail”, some functions you are familiar if you or worpress code.
So Alf is complete, the reader bored? there too long, you read this far then make throat dry always.
Try to see you, very simple, copy and paste, 1 minute 30 seconds. Too fast, too standard.
If you copy my post, please remember to link the source to me.
This article is useful for you, press like on my help, encourage writing.