wordpress后台加上“浏览次数”功能

将以下函数加入到模板中的functions.php文件当中。

/*显示文章浏览次数*/
function getPostViews($postID){
     $count = get_post_meta($postID,'views', true);
     if($count==''){
         delete_post_meta($postID,'views');
         add_post_meta($postID,'views', '0');
         return "0";
     }
     return $count.'';
}

找到 wordpress3.7\wp-admin\includes\class-wp-posts-list-table.php文件:

在以下行上面加入:$view_num = getPostViews($post->ID);

echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . $pad . $title. '</a>' ;


最终成为:

echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . $pad . $title. '</a>' . '[浏览数:' . $view_num .']' ;

 

300*300
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00601 秒