/** * Tab幻灯片小工具-大海 */ Zib_CFSwidget::create('zib_widget_tab_slider', array( 'title' => 'Tab幻灯片', 'zib_affix' => true, 'zib_show' => true, 'description' => '左侧幻灯片+右侧Tab条,hover切换', 'fields' => array( array( 'id' => 'source_type', 'title' => '数据来源', 'default' => 'custom', 'options' => array('custom' => '自定义', 'category' => '分类文章'), 'type' => 'select', ), array( 'dependency' => array('source_type', '==', 'category'), 'id' => 'cat_id', 'title' => '分类ID', 'type' => 'text', ), array( 'dependency' => array('source_type', '==', 'category'), 'id' => 'orderby', 'title' => '排序方式', 'default' => 'date', 'options' => array('date' => '发布时间', 'modified' => '更新时间', 'comment_count' => '评论数', 'views' => '浏览量', 'rand' => '随机'), 'type' => 'select', ), array( 'dependency' => array('source_type', '==', 'custom'), 'id' => 'items', 'title' => '添加项目(最多5个)', 'type' => 'group', 'button_title' => '添加项目', 'accordion_title_auto' => true, 'accordion_title_number' => true, 'accordion_title_by' => array('title'), 'max' => 5, 'fields' => array( array('id' => 'cover', 'title' => '幻灯片大图', 'type' => 'upload', 'library' => 'image'), array('id' => 'thumb', 'title' => 'Tab缩略图', 'desc' => '留空使用大图', 'type' => 'upload', 'library' => 'image'), array('id' => 'title', 'title' => '标题', 'type' => 'text'), array('id' => 'subtitle', 'title' => '副标题', 'type' => 'text'), array('id' => 'link', 'title' => '链接', 'type' => 'link', 'add_title' => '添加链接', 'edit_title' => '编辑链接', 'remove_title' => '删除链接'), ), ), array('id' => 'widget_height', 'title' => '组件高度', 'default' => 280, 'desc' => '单位px', 'type' => 'number'), array('id' => 'left_width', 'title' => '左侧宽度', 'default' => 70, 'desc' => '百分比', 'type' => 'slider', 'min' => 50, 'max' => 80, 'step' => 5), ), )); function zib_widget_tab_slider($args, $instance) { if (!Zib_CFSwidget::show_class($instance)) return; $items = array(); if (($instance['source_type'] ?? 'custom') === 'category' && !empty($instance['cat_id'])) { $orderby = $instance['orderby'] ?? 'date'; $query_args = array( 'post_status' => 'publish', 'cat' => $instance['cat_id'], 'posts_per_page' => 5, 'ignore_sticky_posts' => 1, 'no_found_rows' => true, 'order' => 'DESC', 'orderby' => in_array($orderby, array('views', 'like', 'favorite')) ? 'meta_value_num' : $orderby, ); if (in_array($orderby, array('views', 'like', 'favorite'))) $query_args['meta_key'] = $orderby; $q = new WP_Query($query_args); while ($q->have_posts()) { $q->the_post(); $p = get_post(); $items[] = array( 'cover' => zib_post_thumbnail('large', '', true, $p), 'thumb' => zib_post_thumbnail('thumbnail', '', true, $p), 'title' => get_the_title(), 'subtitle' => get_the_excerpt() ?: wp_strip_all_tags(get_the_content()), 'link' => get_permalink(), 'target' => '', ); } wp_reset_postdata(); } else { if (empty($instance['items'])) return; foreach ($instance['items'] as $item) { $cover = $item['cover'] ?: zib_get_spare_thumb(); $items[] = array( 'cover' => $cover, 'thumb' => $item['thumb'] ?: $cover, 'title' => $item['title'] ?? '', 'subtitle' => $item['subtitle'] ?? '', 'link' => $item['link']['url'] ?? '', 'target' => $item['link']['target'] ?? '', ); } } if (empty($items)) return; $items = array_slice($items, 0, 5); $h = intval($instance['widget_height'] ?? 280); $lw = intval($instance['left_width'] ?? 70); $id = 'ts-' . uniqid(); $lazy = zib_is_lazy('lazy_other', true); $lazySrc = $lazy ? 'class="fit-cover lazyload" src="' . zib_get_lazy_thumb() . '" data-src' : 'class="fit-cover" src'; echo ''; echo '
