售前咨询
技术支持
渠道合作

wordpress让网站后台所有的文章列表都显示出缩略图的方法

使用过wordpress程序的正在朋友们都应该清楚,在wordpress程序网站后台的文章列表里,默认情况下都是没有文章缩略图显示的。但是我们在后台管理文章列表时,为了更加直观的管理了解文章列表的内容信息,同时也是为了方便管理,需要让所有的文章列表都显示出文章缩略图来,那么这个时候我们需要怎么来实现呢?下面数安时代小编就来给大家详细介绍一下,如何在php虚拟主机环境下实现让wordpress网站后台所有的文章列表都显示出缩略图的效果。

首先我们登入数安时代的控制面板,点击文件管理按钮,在wordpress程序的主题文件夹里找到functions.php这一个文件,的如图1所示:

点击编辑按钮进入文件编辑页面,在代码中的末尾添加一段php函数,代码如下:

if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {

// 在文章列表页与页面列表页添加缩略图列表
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');
}
}
}

// 文章页调用
add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );

// 页面调用
add_filter( 'manage_pages_columns', 'fb_AddThumbColumn' );
add_action( 'manage_pages_custom_column', 'fb_AddThumbValue', 10, 2 );
}

如图2、图3、图4中所示:

代码编辑好了之后点击“提交”按钮,保存文件,这样就可以实现让wordpress网站后台所有的文章列表都显示出缩略图的效果了。
温馨提示:该技术解决方案的是由数安时代客服为我们空间客户处理该问题时提供的处理方法,确保在数安时代能完美实现,因服务较多,客服繁忙,其他主机我们没有过多精力进行大范围测试,不能确保所有虚拟主机都能完美处理,请您理解!


 

上一篇:

下一篇:

相关文章