排行榜模块-日主题V2主题美化二开教程

图片[1]-排行榜模块-日主题V2主题美化二开教程-尚艺博客

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

/**
 * 排行榜
 */
CSF::createWidget('rizhuti_v2_module_rank', array(
    'title' => esc_html__('RI-首页模块 : 排行榜', 'rizhuti-v2'),
    'classname' => 'rizhuti_v2-widget-rank',
    'description' => esc_html__('Displays a 排行榜', 'rizhuti-v2'),
    'fields' => array(
        array(
            'id' => 'home_mode_rank',
            'type' => 'fieldset',
            'title' => '',
            'fields' => array(
                array(
                    'id' => '_title',
                    'type' => 'text',
                    'title' => '标题',
                    'default' => '排行榜',
                ),
                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' => 'catcms',
                    'type' => 'group',
                    'title' => '新建排行榜(至多4个)',
                    'max' => 4,
                    'fields' => array(
                        array(
                            'id' => '_title',
                            'type' => 'text',
                            'title' => '排行榜标题',
                            'default' => '',
                            'desc' => '不设置则自动显示分类名称为标题',
                        ),
                        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' => '_is_all_cat',
                            'type' => 'switcher',
                            'title' => '选择全部分类',
                            'default' => false,
                        ),
 
                        array(
                            'id' => 'nav_cat_id',
                            'type' => 'checkbox',
                            'title' => '参与排行的分类',
                            'placeholder' => '选择分类',
                            'chosen' => true,
                            'multiple' => true,
                            'inline' => true,
                            'options' => 'categories',
                            'dependency' => array('_is_all_cat', '==', 'false'),
                        ),
                        array(
                            'id' => '_blank',
                            'type' => 'switcher',
                            'title' => '新窗口打开导航链接',
                            'default' => true,
                            'dependency' => array('is_cat_nav', '==', 'true'),
                        ),
 
                        array(
                            'id' => 'orderby',
                            'type' => 'radio',
                            'title' => '排序方式',
                            'inline' => true,
                            'options' => array(
                                'view' => esc_html__('浏览量', 'rizhuti-v2'),
                                'date' => esc_html__('日期', 'rizhuti-v2'),
                                'rand' => esc_html__('随机', 'rizhuti-v2'),
                                'comment_count' => esc_html__('评论数量', 'rizhuti-v2'),
                                'id' => esc_html__('文章ID', 'rizhuti-v2'),
                            ),
                            'default' => 'view',
                        ),
 
                    ),
                ),
            ),
        ),
 
    ),
));
if (!function_exists('rizhuti_v2_module_rank')) {
    function rizhuti_v2_module_rank($args, $instance)
    {
        if (!is_page_template_modular()) {
            return false;
        } //非模块页面不显示
 
        echo $args['before_widget'];
 
        ob_start(); 
     ?>
        <?php if (!empty($instance['home_mode_rank']['catcms'])) :
        $post_count = 0;
        foreach ($instance['home_mode_rank']['catcms'] as $k => $item) {
            if ('1' === $item['_is_all_cat']) {
                $post_count += wp_count_posts()->publish;
            } else {
                foreach ($item['nav_cat_id'] as $v) {
                    $post_count += get_category($v)->count;
                }
            }
        }
        ?>
        <h3 class="section-title section-title1"><span><i
                        class="<?php echo $instance['home_mode_rank']['_icon'] ?>"></i> <?php echo $instance['home_mode_rank']['_title'] ?>
                    </span></h3>
        <div class="home-section-ranks" id="h_rank">
            <div class="container">
                <div class="section-content">
                    <div class="ranks-content">
                        <div class="ranks-bar">
                            <h4 class="total">榜单合计 <em
                                        class="total_num"><?php echo $post_count; ?></em> 篇</h4>
                            <ul data-tabs style="padding-left: 0">
                                <?php foreach ($instance['home_mode_rank']['catcms'] as $k => $item) {
                                    $title = $item['_title'];
                                    $icon = $item['_icon'];
                                    if ($k === 0) {
                                        echo <<<EOT
<li id="rank-$k" class="ranking-post current" data-source="inspiration"><a><i class="$icon"></i>$title</a></li>
EOT;
                                    } else {
                                        echo <<<EOT
<li id="rank-$k" class="ranking-post" data-source="inspiration"><a><i class="$icon"></i>$title</a></li>
EOT;
                                    }
                                } ?>
                            </ul>
                        </div>
                        <?php
                        echo <<< EOT
<script>
var list_rank;
$(function() {
    $("#rank-0,#rank-1,#rank-2,#rank-3").click(function(){
        $("#rank-0,#rank-1,#rank-2,#rank-3").removeClass('current');
        $(this).addClass('current');
        list_rank = '#list-' + $(this).attr("id");
        $("#list-rank-0,#list-rank-1,#list-rank-2,#list-rank-3").hide();
        $(list_rank).show();
    });
});
</script>
EOT; ?>
                        <div class="ranks-main">
                            <div class="rank-results">
                                <?php foreach ($instance['home_mode_rank']['catcms'] as $k => $item) {
                                    if ($item['orderby'] === 'view') {
                                        $args = array(
                                            'ignore_sticky_posts' => true,
                                            'post_status' => 'publish',
                                            'posts_per_page' => 5,
                                            'meta_key' => '_views',
                                            'orderby' => 'meta_value_num',
                                            'order' => 'DESC'
                                        );
                                    } else {
                                        $args = array(
                                            'ignore_sticky_posts' => true,
                                            'post_status' => 'publish',
                                            'posts_per_page' => 5,
                                            'orderby' => $item['orderby'],
                                            'order' => 'DESC'
                                        );
                                    }
 
                                    if ($item['_is_all_cat'] === '0' || $item['_is_all_cat'] === '') {
                                        if (empty($item['nav_cat_id'])) {
                                            $args['category__in'] = [md5(123)];
                                        } else {
                                            $args['category__in'] = $item['nav_cat_id'];
                                        }
                                    }
 
                                    $wp_query = new WP_Query($args);
                                    $i = 0;
                                    if ($k == 0) {
                                        echo '<div class="items" id="list-rank-' . $k . '">';
                                    } else {
                                        echo '<div class="items" id="list-rank-' . $k . '" style="display: none;">';
                                    }
                                    while ($wp_query->have_posts()) : $wp_query->the_post();
                                        global $post;
                                        if (empty($sizes)) {
                                            $thum_arr_px = _cao('thumb_px');
                                            $_w = (!empty($thum_arr_px)) ? (int)$thum_arr_px['width'] : 300;
                                            $_h = (!empty($thum_arr_px)) ? (int)$thum_arr_px['height'] : 200;
                                        } else {
                                            $_w = (int)$sizes['width'];
                                            $_h = (int)$sizes['height'];
                                        }
                                        $modular = _cao('thumb_type');
                                        $src = _get_post_thumbnail_url($post);
                                        if ($modular == 'php' && !_img_is_gif($src)) {
                                            $thumb_url = get_template_directory_uri() . '/timthumb.php?src=' . $src . '&h=' . $_h . '&w=' . $_w . '&zc=1&a=c&q=100&s=1';
                                        } elseif ($modular == 'other' && !_img_is_gif($src)) {
                                            $thumbnail_other = _cao('thumbnail_other', '');
                                            $thumb_url = $src . $thumbnail_other;
                                        } else {
                                            $thumb_url = $src;
                                        }
 
                                        $categoriy = '';
                                        $categories = get_the_category();
                                        foreach ($categories as $k => $v) {
                                            if ($k > 0) {
                                                break;
                                            }
 
                                            if ($k === 1) {
                                                $categoriy .= ' | ' . '<a href="' . get_category_link($v->term_id) . '">' . $v->name . '</a>';
                                            } else {
                                                $categoriy .= '<a href="' . get_category_link($v->term_id) . '">' . $v->name . '</a>';
                                            }
                                        }
                                        $author = get_the_author_posts_link();
 
                                        $i++;
                                        ?>
                                        <div class="item">
                                            <div class="item-num num-<?php echo $i ?>"><span
                                                        class="num"><?php echo $i ?></span></div>
                                            <div class="item-thumb"><a href="<?php the_permalink() ?>" target="_blank">
                                                    <i
                                                            class="thumb "
                                                            style="background-image:url(<?php echo $thumb_url ?>)"></i>
                                                </a></div>
                                            <div class="item-title"><a href="<?php the_permalink() ?>" target="_blank">
                                                    <?php the_title(); ?></a></div>
                                            <div class="item-cat" style="text-align: center"><?php echo $categoriy; ?></div>
                                            <div class="item-author">
                                                <?php echo $author; ?>
                                            </div>
                                            <div class="item-views">
                                                <div class="un-hover"><em><?php echo _get_post_views(); ?></em> 观众</div>
                                            </div>
                                        </div>
                                    <?php endwhile;
                                    echo '</div>';
                                } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </div>
        </div>
    <?php endif; ?>
        <?php
 
        echo ob_get_clean();
 
        echo @$args['after_widget'];
 
    }
}

最后进入 后台 – 外观 – 自定义 – 额外CSS 添加下面的代码:

感谢您的来访,获取更多精彩文章请收藏本站。

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

请登录后发表评论

    暂无评论内容