之前本站分享过指定作者文章总浏览数量、整站文章总浏览数量、自定义分类文章数量总数,这篇文章给大家带来分类目录总浏览量统计的教程。
也不难,往下看就知道了:
function fa_get_tax_views($term_id = null) {
if (!$term_id) {
$term = get_queried_object();
$term_id = $term->term_id;
}
if (!$term_id) return;
$view = get_term_meta($term_id , '_views' , true) ? get_term_meta($term_id , '_views' , true) : 0;
return $view;
}
function fa_set_tax_views() {
if (!is_category() && !is_tag()) return;
$term = get_queried_object();
$term_id = $term->term_id;
$view = fa_get_tax_views($term_id);
update_term_meta($term_id, '_views' , $view + 1);
}
add_action('get_header', 'fa_set_tax_views');
首先我们把上面核心代码添加到主题的functions.php文件内,然后在前台调用,调用代码为:
这样就完成了WordPress分类目录总浏览量统计,你有没有学会呢?
文章来源于互联网:WordPress分类目录总浏览量统计
There are some attention-grabbing cut-off dates in this article however I don?t know if I see all of them heart to heart. There may be some validity however I will take hold opinion until I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as properly