本文标签: wordpress
1、将下面的代码加入到functis模版中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Views'; } function setPostViews($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); } } |
2、在主题single模板循环中加入:
1 |
<?php setPostViews(get_the_ID()); ?> |
这个作用是增加阅读次数。
3、在调用的地方加入:
1 |
<?php echo getPostViews(get_the_ID()); ?> |
此外,如果想在其他位置显示阅读次数,把下面的代码加入到function模板中:
1 |
remove_action('wp_head','adjacent_posts_rel_link_wp_head',10,0); |
参考:http://zmingcx.com/no-plugin-wordpress-reads.html
声明: 本文由( liva )原创编译,转载请保留链接: 给wordpress增加阅读次数 无插件
给wordpress增加阅读次数 无插件:等您坐沙发呢!
发表评论
