WordPress 技巧:在后台日志列表显示附件数量
如果你网站的图片等附件非常多,你想在 WordPress 后台日志列表页面能够显示出附件的数量,你可以在当前主题的 functions.php
添加如下代码:
add_filter('manage_posts_columns', 'wpjam_manage_posts_columns_attachment_count', 5);
function wpjam_manage_posts_columns_attachment_count($columns){
$columns['attachments_count'] = '附件数';
return $columns;
}
add_action('manage_posts_custom_column', 'wpjam_namage_posts_custom_columns_attachment_count', 5, 2);
function wpjam_namage_posts_custom_columns_attachment_count($column_name, $id){
if($column_name === 'attachments_count'){
echo count(get_children(array('post_parent'=>$id)));
}
}