WordPress 技巧:在后台日志列表显示附件数量

如果你网站的图片等附件非常多,你想在 WordPress 后台日志列表页面能够显示出附件的数量,你可以在当前主题的 functions.php 添加如下代码:

<br />
add_filter('manage_posts_columns', 'wpjam_manage_posts_columns_attachment_count', 5);<br />
function wpjam_manage_posts_columns_attachment_count($columns){<br />
    $columns['attachments_count'] = '附件数';<br />
    return $columns;<br />
}</p>
<p>add_action('manage_posts_custom_column', 'wpjam_namage_posts_custom_columns_attachment_count', 5, 2);<br />
function wpjam_namage_posts_custom_columns_attachment_count($column_name, $id){<br />
    if($column_name === 'attachments_count'){<br />
        echo count(get_children(array('post_parent'=>$id)));<br />
    }<br />
}<br />
标签:

热门文章