WordPress根据文章阅读量赋热帖图标-仿discuz

WordPress根据文章阅读量赋热帖图标-仿discuz:仿照discuz论坛。当文章浏览量大于规定值,如500后,自动在文章的顶部加一个图标,图标内容可以是热帖、优秀、精华等。演示效果和实现代码如下:

 

 

WordPress根据文章阅读量赋热帖图标-仿discuz

 

 

实现代码

[hide]

通用教程,适合WordPress美化,也适合子比主题和7B2主题美化

将下面的代码添加到主题的function.php文件即可

/*文章开头大于50浏览量出现热帖图片*/
add_filter('the_content', 'add_lu_content_beforde');
function add_lu_content_beforde( $content ) {
 if( !is_feed() && !is_home() && is_singular() && is_main_query() ) {
   $viewnum= (int) get_post_meta( get_the_ID(), 'views', true );
      if ($viewnum > 500){  //这里是浏览量大于500
        $before_content = '<img style="position: absolute; right: 10px;  pointer-events: none; z-index: 10;" src="https://www.lurenfen.com/media/2023/10/002.gif" alt="热帖" >'; //图片地址修改成自己的
      $lu = $before_content . $content;
        }
   else{$lu = $content;}}
 return $lu;
}

[/hide]

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

    暂无评论内容