Views-on in theme radiate (WordPress)

Install WP-PostViews plugin and activate it.

Open file /wp-content/themes/radiate/inc/template-tags.php

Find function radiate_posted_on(), and add the following code at the end of this function.

printf( '<span class="view-on"><span class="views">');
if(function_exists('the_views')) { the_views(); }
printf('</span></span>');

Go back to dashboards, Click Appearence->Edit and open style.css

Find the following code

.entry-meta .posted-on:before,
.entry-meta .byline:before,
.entry-meta .cat-links:before,
.entry-meta .tags-links:before,
.entry-meta .comments-link:before,
.entry-meta .edit-link:before{
display: inline-block;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font: normal 22px/1 'Genericons';
    vertical-align: top;
}

and add .entry-meta .view-on:before and an additional comma(,). Ande the code will change into

.entry-meta .posted-on:before,
.entry-meta .byline:before,
.entry-meta .cat-links:before,
.entry-meta .tags-links:before,
.entry-meta .comments-link:before,
.entry-meta .edit-link:before,
.entry-meta .view-on:before {
display: inline-block;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font: normal 22px/1 'Genericons';
    vertical-align: top;
}

Furthermore,  add the following code anywhere you like in style.css

.entry-meta .view-on:before {
    content: 'f403';
}

.entry-meta .views {
    padding: 5px;
}

Save it, and clean cache of the brower and refresh article page.

Congratulations if you can see views on in the article page.

 

============ 更新2020-05-04==============

更新完WP-PostViews后,无法增加阅读量的计数了,就禁用了WP-PostViews,并安装了另外一款插件:Post Views Counter。关于Post Views Counter的介绍网上有很多,此处不再赘述。下面讲一下个性化设置的步骤。

首先,在Post Views Counter的设置界面->显示选项卡下,将“浏览量标签”和“图标类”清空,并将位置改为“手动”。

然后进入插件->插件编辑器,在右上角选择“Post Views Counter”插件,找到打开functions.php这个文件,并找到function pvc_post_views这一行,修改函数pvc_post_views中

$html = apply_filters(
			'pvc_post_views_html', '<div class="post-views post-' . $post_id . ' entry-meta">
			' . ($options['display_style']['icon'] && $icon_class !== '' ? $icon : '') . '
			' . ($options['display_style']['text'] ? '<span class="post-views-label">' . $label . ' </span>' : '') . '
			<span class="post-views-count">' . number_format_i18n( $views ) . '</span>
			</div>', $post_id, $views, $label, $icon
		);

$html = apply_filters(
			'pvc_post_views_html', number_format_i18n( $views ), $post_id, $views, $label, $icon
		);

这样,就定制完成了。

PS:

Post Views Counter会查找表名为xxxx_post_views这张表中type=4的记录作为浏览量。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

13 − 2 =

+ 82 = 90