HEX
Server: nginx/1.28.0
System: Linux yisu-68a5f20334161 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: www (1000)
PHP: 8.2.28
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/q.autos58.cn/wp-content/themes/kong20/inc/options/widget-options.php
<?php if (!defined('ABSPATH')) {die;}
// Create a widget hua_widget_right
/**
 * 侧边栏分类文章展示
 */
$imagepath =  get_template_directory_uri() . '/images/';

CSF::createWidget('hua_widget_post_itema', array(
    'title'       => 'Hua-侧栏文章带数字',
    'classname'   => 'right-list6',
    'description' => '页面右侧,显示文章列表,根据自己需求,可多次使用于各个页面的右侧。',
    'fields'      => array(
        array(
            'id'    => 'title',
            'type'  => 'text',
            'title' => '标题',
        ),
        array(
            'id'          => 'category_mode',
            'type'        => 'select',
            'title'       => '分类选择模式',
            'options'     => array(
                'all'      => '全站文章',
                'current'  => '当前分类',
                'specific' => '选择特定分类'
            ),
            'default'     => 'current',
            'desc'        => '选择"全站文章"或手动指定多个分类',
        ),
        array(
            'id'          => 'specific_category',
            'type'        => 'select',
            'title'       => '选择分类(可多选)',
            'placeholder' => '按住Ctrl/Cmd键多选',
            'options'     => 'hua_get_category_options',
            'default'     => array(),  // 默认空数组
            'multiple'    => true,     // 启用多选
            'chosen'      => true,     // 启用美观的搜索下拉(需框架支持)
            'dependency'  => array('category_mode', '==', 'specific'),
            'desc'        => '可同时选择多个分类',
        ),
       
        array(
            'id'      => 'count',
            'type'    => 'text',
            'title'   => '文章数量',
            'default' => 10,
        ),
       array(
            'id'      => 'orderby',
            'type'    => 'select',
            'title'   => '排序方式',
            'options' => array(
                'date'          => '日期',
                'rand'          => '随机',
                'views'         => '阅读量',
                //'hua_thumbup'   => '点赞',
                'modified'      => '最近编辑时间',
                'ID'            => '文章ID',
            ),
        ),

    ),
));
if (!function_exists('hua_get_category_options')) {
    function hua_get_category_options() {
        $options = array();
        $categories = get_categories(array(
            'orderby' => 'name',
            'order'   => 'ASC',
            'hide_empty' => false,
        ));
        
        foreach ($categories as $category) {
            $options[$category->term_id] = $category->name;
        }
        
        return $options;
    }
}
if (!function_exists('hua_widget_post_itema')) {
    function hua_widget_post_itema($args, $instance) {
      
        $instance = array_merge( array( 
            'category_mode' => 'current',
            'specific_category' => 0,
            'orderby' => 'date',
            'count' => 6,
        ), $instance);


        echo $args['before_widget'];

        if (!empty($instance['title'])) {
            echo $args['before_title'] . $instance['title'] . $args['after_title'];
        }
        $category_id = 0;
        switch ($instance['category_mode']) {
            case 'all':
                // 全站 - no category filter
                $category_id = 0;
                break;
                
            case 'current':
                // 当前分类
                if (is_single()) {
                    $categories = get_the_category();
                    $category_id = !empty($categories) ? $categories[0]->cat_ID : 0;
                } elseif (is_category()) {
                    $category_id = get_queried_object_id();
                }
                break;
                
            case 'specific':
                // 特定分类
                $category_id = $instance['specific_category'];
                break;
        }

        // 查询参数
        $_args = array(
            'ignore_sticky_posts' => true,
            'post_status'         => 'publish',
            'posts_per_page'      => (int)$instance['count'],
        );

        // 添加分类参数(如果不是全站)
        if ($category_id > 0) {
            $_args['cat'] = $category_id;
        }

        // 排序方式
        $orderby = $instance['orderby'];
        if ($orderby !== 'views' && $orderby !== 'hua_thumbup') {
            $_args['orderby'] = $orderby;
        } else {
            $_args['orderby'] = 'meta_value_num';
            $_args['meta_key'] = $orderby;
            $_args['order'] = 'DESC';
        }
        

        $PostData = new WP_Query($_args);
         $i = 0;
        ob_start();
        ?>
        <ul class="hot-item">
        <?php while ($PostData->have_posts()): $PostData->the_post();$i++;?>
            <li><span class="badge color<?php echo $i;?>"><?php echo $i;?></span><a title="<?php echo get_the_title() ;?>" href="<?php echo esc_url( get_permalink() );?>" target="_blank"><?php echo get_the_title() ;?></a></li>
        <?php endwhile;?>
       </ul>
        <?php wp_reset_postdata(); echo ob_get_clean(); echo $args['after_widget'];
    }
}

// 广告展示小工具
CSF::createWidget('hua_widget_ads', array(
    'title'       => 'Hua-广告展示',
    'classname'   => 'widget-adss',
    'description' => '自定义广告图',
    'fields'      => array(
        array(
            'id'    => 'title',
            'type'  => 'text',
            'title' => '标题',
        ),
        array(
            'id'      => '_color',
            'type'    => 'color',
            'default' => '#ff6a6d',
            'title'   => '背景颜色',
        ),
        array(
            'id'         => '_title',
            'type'       => 'text',
            'title'      => '广告标题',
            'default'    => '自定义广告位标题',
        ),
        array(
            'id'      => '_text',
            'type'    => 'textarea',
            'title'   => '广告描述',
            'default' => '这里是广告描述,提供极简高品质的wordpress企业主题及博客主题,助你快速启用wordpress站点。关注huatheme.com,主题永久免费更新!',
        ),
        array(
            'id'         => '_href',
            'type'       => 'text',
            'title'      => '链接地址',
            'default'    => 'https://www.huatheme.com/',
        ),
    ),
));
if (!function_exists('hua_widget_ads')) {
    function hua_widget_ads($args, $instance)
    {
        // if ( ! empty( $instance['title'] ) ) {
        //   echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
        // }
        // start
        $_color   = $instance['_color'];
        $_title     = $instance['_title'];
        $_text     = $instance['_text'];
        $_href     = $instance['_href'];
        echo '<div class="widget-adss">';
        echo '<a class="asr" href="'.$_href.'" target="_blank" style="background-color:'.$_color.'"><h4>'.$_title.'</h4><h5>'.$_text.'</h5><span class="btn btn-outline">立即查看</span></a>';
        echo '</div>';
        
        // end
    }
}