有没有想过在WordPress后台文章列表显示每篇文章所用的附件数量?下面的代码可以帮助你实现这个功能,你只需将代码添加到主题的 functions.php 文件即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 | add_filter('manage_posts_columns', 'posts_columns_attachment_count', 5); add_action('manage_posts_custom_column', 'posts_custom_columns_attachment_count', 5, 2); function posts_columns_attachment_count($defaults){ $defaults['wps_post_attachments'] = __('Att'); return $defaults; } function posts_custom_columns_attachment_count($column_name, $id){ if($column_name === 'wps_post_attachments'){ $attachments = get_children(array('post_parent'=>$id)); $count = count($attachments); if($count !=0){echo $count;} } } |
add_filter('manage_posts_columns', 'posts_columns_attachment_count', 5); add_action('manage_posts_custom_column', 'posts_custom_columns_attachment_count', 5, 2); function posts_columns_attachment_count($defaults){ $defaults['wps_post_attachments'] = __('Att'); return $defaults; } function posts_custom_columns_attachment_count($column_name, $id){ if($column_name === 'wps_post_attachments'){ $attachments = get_children(array('post_parent'=>$id)); $count = count($attachments); if($count !=0){echo $count;} } }
到此这篇关于在WordPress后台文章列表显示文章所用的附件数量就介绍到这了。因为有了梦想,才可以拥有奋斗的目标,而这些目标凝结成希望的萌芽,在汗水与泪水浇灌下,绽放成功之花。更多相关在WordPress后台文章列表显示文章所用的附件数量内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!