网站统计小工具-日主题V2主题美化二开教程

网站统计小工具-日主题V2主题美化二开教程-58模板库

利用宝塔或则FTP打开/rizhuti-v2/inc/options下的widget-options.php文件放入以下代码在第2行下面:

/**
 * 网站统计
 */
CSF::createWidget('rizhuti_v2_module_count', array(
    'title' => esc_html__('RI-首页模块 : 网站统计', 'rizhuti-v2'),
    'classname' => 'rizhuti_v2-widget-parallax reds-count-widget',
    'description' => esc_html__('Displays a 网站统计模块.', 'rizhuti-v2'),
    'fields' => array(
 
        array(
            'id' => 'image',
            'type' => 'upload',
            'title' => esc_html__('背景图', 'rizhuti-v2'),
            'default' => get_template_directory_uri() . '/assets/img/top-bg.jpg',
        ),
        array(
            'id' => 'is_text',
            'type' => 'switcher',
            'title' => esc_html__('显示内容介绍', 'rizhuti-v2'),
            'default' => true,
            'sanitize' => false,
        ),
        array(
            'id' => 'is_button',
            'type' => 'switcher',
            'title' => esc_html__('显示按钮', 'rizhuti-v2'),
            'default' => true,
            'sanitize' => false,
        ),
        array(
            'id' => 'text',
            'type' => 'text',
            'title' => esc_html__('内容介绍', 'rizhuti-v2'),
            'default' => esc_html__('内容介绍', 'rizhuti-v2'),
            'dependency' => array('is_text', '==', 'true'),
            'sanitize' => false,
        ),
        array(
            'id' => 'button_one',
            'type' => 'fieldset',
            'title' => '按钮一',
            'dependency' => array('is_button', '==', 'true'),
            'fields' => array(
                array(
                    'id' => '_title',
                    'type' => 'text',
                    'title' => '标题',
                    'default' => '开通VIP',
                ),
                array(
                    'id' => '_link',
                    'type' => 'text',
                    'title' => '链接',
                    'default' => '/user?action=vip',
                ),
            ),
        ),
        array(
            'id' => 'button_two',
            'type' => 'fieldset',
            'title' => '按钮二',
            'dependency' => array('is_button', '==', 'true'),
            'fields' => array(
                array(
                    'id' => '_title',
                    'type' => 'text',
                    'title' => '标题',
                    'default' => '资源推荐',
                ),
                array(
                    'id' => '_link',
                    'type' => 'text',
                    'title' => '链接',
                    'default' => '#',
                ),
            ),
        ),
        array(
            'id' => 'user_count',
            'type' => 'fieldset',
            'title' => '会员总数统计',
            'fields' => array(
                array(
                    'id' => '_count',
                    'type' => 'text',
                    'title' => '数量',
                    'desc' => '留空调用系统数据',
                    'default' => '',
                ),
                array(
                    'id' => '_color',
                    'type' => 'color',
                    'title' => '悬浮颜色',
                    'default' => '#ec2546',
                ),
                array(
                    'id' => '_icon',
                    'type' => 'text',
                    'title' => '图标',
                    'default' => 'fa fa-home',
                    'desc' => '请使用<a target="_blank" href="https://fontawesome.com/icons">Font Awesome</a>图标,例子<code>fa fa-home</code>',
                ),
            ),
        ),
        array(
            'id' => 'post_count',
            'type' => 'fieldset',
            'title' => '资源总数统计',
            'fields' => array(
                array(
                    'id' => '_count',
                    'type' => 'text',
                    'title' => '数量',
                    'desc' => '留空调用系统数据',
                    'default' => '',
                ),
                array(
                    'id' => '_color',
                    'type' => 'color',
                    'title' => '悬浮颜色',
                    'default' => '#ec2546',
                ),
                array(
                    'id' => '_icon',
                    'type' => 'text',
                    'title' => '图标',
                    'default' => 'fa fa-home',
                    'desc' => '请使用<a target="_blank" href="https://fontawesome.com/icons">Font Awesome</a>图标,例子<code>fa fa-home</code>',
                ),
            ),
        ),
        array(
            'id' => 'post_count_for_week',
            'type' => 'fieldset',
            'title' => '本周发布统计',
            'fields' => array(
                array(
                    'id' => '_count',
                    'type' => 'text',
                    'title' => '数量',
                    'desc' => '留空调用系统数据',
                    'default' => '',
                ),
                array(
                    'id' => '_color',
                    'type' => 'color',
                    'title' => '悬浮颜色',
                    'default' => '#ec2546',
                ),
                array(
                    'id' => '_icon',
                    'type' => 'text',
                    'title' => '图标',
                    'default' => 'fa fa-home',
                    'desc' => '请使用<a target="_blank" href="https://fontawesome.com/icons">Font Awesome</a>图标,例子<code>fa fa-home</code>',
                ),
            ),
        ),
        array(
            'id' => 'post_count_for_day',
            'type' => 'fieldset',
            'title' => '今日发布统计',
            'fields' => array(
                array(
                    'id' => '_count',
                    'type' => 'text',
                    'title' => '数量',
                    'desc' => '留空调用系统数据',
                    'default' => '',
                ),
                array(
                    'id' => '_color',
                    'type' => 'color',
                    'title' => '悬浮颜色',
                    'default' => '#ec2546',
                ),
                array(
                    'id' => '_icon',
                    'type' => 'text',
                    'title' => '图标',
                    'default' => 'fa fa-home',
                    'desc' => '请使用<a target="_blank" href="https://fontawesome.com/icons">Font Awesome</a>图标,例子<code>fa fa-home</code>',
                ),
            ),
        ),
        array(
            'id' => 'run_date',
            'type' => 'fieldset',
            'title' => '稳定运行时长统计',
            'fields' => array(
                array(
                    'id' => '_count',
                    'type' => 'date',
                    'title' => '数量',
                    'desc' => '设置一个起始时间,系统将自动计算经过的天数',
                    'default' => '12/1/2020',
                ),
                array(
                    'id' => '_color',
                    'type' => 'color',
                    'title' => '悬浮颜色',
                    'default' => '#ec2546',
                ),
                array(
                    'id' => '_icon',
                    'type' => 'text',
                    'title' => '图标',
                    'default' => 'fa fa-home',
                    'desc' => '请使用<a target="_blank" href="https://fontawesome.com/icons">Font Awesome</a>图标,例子<code>fa fa-home</code>',
                ),
            ),
        ),
 
    ),
));
if (!function_exists('rizhuti_v2_module_count')) {
    function rizhuti_v2_module_count($args, $instance)
    {
        if (!is_page_template_modular()) {
            return false;
        } //非模块页面不显示
 
        echo $args['before_widget'];
 
        ob_start(); ?>
        <div class="module parallax">
            <?php if (!empty($instance['image'])): ?>
                <img class="jarallax-img lazyload" data-src="<?php echo esc_url($instance['image']); ?>"
                     src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
                     alt="<?php echo esc_attr($instance['title']); ?>">
            <?php endif;
 
            if ($instance['text'] != ''): ?>
                <?php
                $users = wp_list_authors('echo=0&exclude_admin=0&hide_empty=0&optioncount=1&style=0');
                $users = explode(',', $users);
                ?>
                <div class="container">
                    <div class="mobanweb">
                        <ul class="data-items">
                            <li><i class="mdi <?php echo $instance['user_count']['_icon'] ?>"></i><strong
                                        data-count="97596"
                                        class="active"><?php echo $instance['user_count']['_count'] ?: count($users) ?></strong><span>会员总数(位)</span>
                            </li>
                            <li><i class="mdi <?php echo $instance['post_count']['_icon'] ?>"></i><strong
                                        data-count="34774"
                                        class="active"><?php echo $instance['post_count']['_count'] ?: wp_count_posts()->publish ?></strong><span>资源总数(个)</span>
                            </li>
                            <li><i class="mdi <?php echo $instance['post_count_for_week']['_icon'] ?>"></i><strong
                                        data-count="841940"
                                        class="active"><?php echo $instance['post_count_for_week']['_count'] ?: ft_get_posts_count_from_this_week() ?></strong><span>本周发布(个)</span>
                            </li>
                            <li><i class="mdi <?php echo $instance['post_count_for_day']['_icon'] ?>"></i><strong
                                        data-count="2377"
                                        class="active"><?php echo $instance['post_count_for_day']['_count'] ?: ft_get_posts_count_from_today() ?></strong><span>今日发布(个)</span>
                            </li>
                            <li><i class="mdi <?php echo $instance['run_date']['_icon'] ?>"></i><strong
                                        data-count="7082"
                                        class="active"><?php echo (int)((time() - strtotime($instance['run_date']['_count'])) / 86400); ?></strong><span>稳定运行(天)</span>
                            </li>
                        </ul>
                    </div>
                    <?php if($instance['is_text'] === null ? true : $instance['is_text']):?>
                    <h4 class="entry-title"><?php echo $instance['text'] ?></h4>
                    <?php endif;?>
                    <?php if($instance['is_button'] === null ? true : $instance['is_button']):?>
                    <a target="_blank" class="button"
                       href="<?php echo $instance['button_one']['_link'] ?>"><?php echo $instance['button_one']['_title'] ?></a>
                    <a target="_blank" class="button transparent"
                       href="<?php echo $instance['button_two']['_link'] ?>"><?php echo $instance['button_two']['_title'] ?></a>
                    <?php endif;?>
                </div>
            <?php endif;
 
            if (!empty($instance['link'])): ?>
                <a class="u-permalink"
                   href="<?php echo esc_url($instance['link']); ?>"<?php echo esc_attr($instance['new_tab'] ? ' target="_blank"' : ''); ?>></a>
            <?php endif; ?>
        </div> <?php
 
        echo ob_get_clean();
 
        echo $args['after_widget'];
 
    }
}

随后把这行代码放在主题的functions.php文件最底部即可

发表回复

后才能评论