7B2主题首页 文章角标 后台可自定义设置任何文字

怎么来设置文章角标,一直都是很多小伙伴想要的,今天就来说一说这个功能怎么做吧,喜欢就加一个看看吧。

一.角标文字填写

此部分主要是构建在写文章的时候填写在文章图片上显示的文字和背景颜色。

如图:

打开路径b2/Modules/Settings/Post.php,查找”是否显示标签”,在后方加上如下代码:

        //角标文字填写
        $post_meta->add_field(array(
            'name' => __('文章角标显示','b2'),
            'id'   => 'post_style_art',
            'type' => 'textarea_code',
            'options' => array( 'disable_codemirror' => true ),
            'desc'=>__('请尽量填写两个字//不选择则不显示','b2'),
            'default' => self::$default_settings['post_style_art'],
            'attributes' => array('style'    => 'width: auto; height: 50px;padding: 5px;border-radius: 2px;')
        ) );
        //角标背景颜色
        $post_meta->add_field(array(
            'name' => __('文章角标背景颜色','b2'),
            'id'   => 'post_art_color',
            'type' => 'colorpicker',
            'options' => array( 'disable_codemirror' => true ),
            'desc'=>__('选择你喜欢的颜色,它将成为角标的背景颜色','b2'),
        ) ); 

保存关闭此文件。

二.后台全局控制

此部分主要是构建全局后台,是否显示文章角标和默认角标,默认角标不填写,则没有设置角标的文章都不显示文章角标。

下载千度免费版子主题

此部分代码可写在子主题后台上

       $ict_branch->add_field(array(
            'name' => __('文章角标显示','b2'),
            'id'   => 'ict_adv_jiaobiao',
            'type'             => 'select',
            'default'          => self::$default_settings['ict_adv_jiaobiao'],
            'options'          => array(
                1 => __( '开启', 'b2' ),
                0   => __( '关闭', 'b2' )
            ),
            'description'=>'开启后,它将会显示在文章图片上方',
        ));
        
         $ict_branch->add_field(array(
            'name' => __('文章角标默认值','b2'),
            'id'   => 'ict_adv_jiaobiao_write',
            'type'             => 'text',
            'default'          => self::$default_settings['ict_adv_jiaobiao_write'],
            'desc'=>__('开启后,它将会显示在文章图片上方。','b2')
        ));

三.前端显示设置

打开文件b2/Modules/Templates/Modules/Posts.php,仔细看此文件的注释,此文件主要就是文章列表下文章的布局方式,主要的五种布局方式都在此文件下,此处主要以网格模式做演示,如下图:

将如下的代码都放置与横线标注的中间,保存文件即可。

            //文章角标
            $page_jiaobiao_open =b2_get_option('template_Branch','ict_adv_jiaobiao',true);
            $page_jiaobiao_default =b2_get_option('template_Branch','ict_adv_jiaobiao_write',true);            
            $ymetaValue = apply_filters('b2_post_1_get_type',get_post_meta($v['id'],'post_style_art',true));
            $ymetaValue_color=apply_filters('b2_post_1_get_type',get_post_meta($v['id'],'post_art_color',true));
            $tab_tian = $page_jiaobiao_default ? '<div class="tian yue" style="background-color: '.$ymetaValue_color.';">'.$page_jiaobiao_default.'</div>' :'';
            $tab_tians='';
            if($page_jiaobiao_open){
                if($ymetaValue){
                    $tab_tians = '<div class="tian yue" style="background-color: '.$ymetaValue_color.';">'.$ymetaValue.'</div>';
                }else{
                    $tab_tians = $tab_tian;                
                }
            }

转载于:https://www.termilk.com/520.html

相关文章

评论 (0)