A-A+

wordpress文章列表显示附件数量

2014年12月26日 PHP开源系统 评论 1 条 阅读 140 views 次

现在越来越多的 wordpress 站点文章都插入了附件文件,附件越来越多的时候就不太好管理了,有时候我们需要知道哪篇文章里插入了多少附件文件,这个时候不得不重新进行编辑文章,看下这篇文章有几个附件,这个是非常不方便的,如果可以在后台文章列表页查看附件的数量就方便多了,实现这个功能需要在主题的functions.php下面加入下面的代码:

add_filter('manage_posts_columns', 'v7v3_attachment_count', 5);
add_action('manage_posts_custom_column', 'v7v3_columns_attachmen
t_count', 5, 2);
function v7v3_attachment_count($defaults){
    $defaults['wps_post_attachments'] = __('附件数量');
    return $defaults;
}
function v7v3_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;}
    }
}//代码来源于:v7v3.com

实现后的效果图如下所示:

如果文章中包含附件则会显示有多少个附件,如果没有附件的话则会什么都不显示。

标签:

1 条留言  访客:1 条  博主:0 条

  1. 好运品牌鞋

    这样的知识好,对于需要者非常有用。

给我留言