内容简介:
WordPress根据文章阅读量赋热帖图标-仿discuz:仿照discuz论坛,起源子比主题。当文章浏览量大于规定值,如500后,自动在文章的顶部加一个图标,图标内容可以是热帖、优秀、精华等。演示效果和实现代码如下:
效果图片:
实现代码:
通用教程,适合WordPress美化,也适合子比主题和7B2主题美化,主题的浏览量一般都是views
,这个在之前说过,大家可以去看看3种方法实现wordpress网站批量修改增加文章阅读量将下面的代码添加到主题的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://pic2.ziyuan.wang/user/17682340266/2025/03/rt_29e3c6cb6182e.png" alt="热帖" >'; //图片地址修改成自己的 $lu = $before_content . $content; } else{$lu = $content;}} return $lu; }
其他热贴图:
https://pic2.ziyuan.wang/user/17682340266/2025/03/bl_6d37d88ef0146.png
https://pic2.ziyuan.wang/user/17682340266/2025/03/jh_314b536af4b48.png
https://pic2.ziyuan.wang/user/17682340266/2025/03/rt_29e3c6cb6182e.png
https://pic2.ziyuan.wang/user/17682340266/2025/03/tj_b45c291a3eeff.png
https://pic2.ziyuan.wang/user/17682340266/2025/03/yc_c180ae421dc17.png
https://pic2.ziyuan.wang/user/17682340266/2025/03/yx_c86a886e5ea42.png
https://pic2.ziyuan.wang/user/17682340266/2025/03/zd_07587864addb4.png
评论(0)