由奇它论坛@老白转载自网络,适用于WordPress网站B2主题的美化教程,其他主题自测。此方式只改了,其中一个文章列表样式(网格模式),其他的文章列表样式可按照同方法即可。
1.美化演示效果
2.B2主题实现教程
①.打开B2主题文件:/b2/Modules/Settings/Post.php 464处加入以下代码:
(转载自onecad,原文地址:https://www.onecad.cn/237/,感谢站长的分享)
// 文章添加角标开始-https://www.qitabbs.com/17373.html $post_meta = new_cmb2_box(array( 'id' => 'b2_post_onecad_jb', 'title' => __( '文章角标', 'b2' ), 'object_types' => array('post','document','page'), 'context' => 'normal', 'priority' => 'high', 'show_names' => true )); $post_meta->add_field(array( 'name' => sprintf(__('列表需要显示角标','b2'),$g_name), 'id' => 'b2_post_onecad_lb', 'type' => 'select', 'options'=>array( 0=>__('推荐','b2'), 1=>__('VIP','b2'), 2=>__('原创','b2'), 3=>__('免费','b2') ), 'default'=>0, 'desc'=> __('支持 HTML,尽量短小才好看。','b2') )); add_filter('post_side_settings', 'wporg_custom'); // 文章添加角标结束-https://www.qitabbs.com/17373.html
②.刷新缓存,在后台文章写作页面,即可看到角标设置项
③.在文章样式列表文件中b2/Modules/Templates/Modules/Posts.php 第108行下方增加:
$b2_post_onecad_lb= get_post_meta($v['id'],'b2_post_onecad_lb',true); if($b2_post_onecad_lb == ''){ $meta_jiaobiao_html ='<span>'.$b2_post_onecad_lb.'</span>'; }else if($b2_post_onecad_lb ==0){ $meta_jiaobiao_html ='<span class="tipss huodong b2-radius">推荐</span>'; }else if($b2_post_onecad_lb ==1){ $meta_jiaobiao_html = '<span class="tipss remen b2-radius">VIP</span>'; }else if($b2_post_onecad_lb ==2){ $meta_jiaobiao_html ='<span class="tipss jingping b2-radius">原创</span>'; }else if($b2_post_onecad_lb ==3){ $meta_jiaobiao_html ='<span class="tipss tuijain b2-radius">免费</span>'; }
④.然后再同文件的第180行下方增加调用‘.$meta_jiaobiao_html.’
⑤.css美化
/*角标CSS-https://www.qitabbs.com/17373.html*/ .tipss { position: absolute; top: 10px; left: 10px; z-index: 1; width: 50px; height: 20px; color: #fff; line-height: 20px; text-align: center; font-size: 13px; z-index: 100; } .yellow {background-color: #ff6000;} .huodong{background:#0693e3} .remen{background:#fcb900} .jingping{background:#cf2e2e} .guanggao{background:#00d084} .tuijain{background:#ff6900} .yuliu{background:#0693e3}
相关的美化教程大家点击分类和文末标签阅读吧!
测试一下看看。