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 “%s”' ), $title ) ) . '">' . $pad . $title. '</a>' ;echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . $pad . $title. '</a>' . '[浏览数:' . $view_num .']' ;
最终成为: