代码来自joe主题~
functions.php添加:
- $JIndexCarousel = new Typecho_Widget_Helper_Form_Element_Textarea(
- 'JIndexCarousel',
- NULL,
- NULL,
- '首页轮播图',
- '介绍:用于显示首页轮播图,请务必填写正确的格式 <br />
- 格式:图片地址 || 跳转链接 || 标题 (中间使用两个竖杠分隔)<br />
- 其他:一行一个,一行代表一个轮播图 <br />
- 例如:<br />
- https://puui.qpic.cn/media_img/lena/PICykqaoi_580_1680/0 || http://baidu.com || 百度一下 <br />
- https://puui.qpic.cn/tv/0/1223447268_1680580/0 || http://v.qq.com || 腾讯视频
- '
- );
- $JIndexCarousel->setAttribute('class', 'col-mb-12 typecho-option setc');
- $form->addInput($JIndexCarousel);
复制代码
调用~
- <div class="container">
- <div id="banner" class="carousel slide" data-bs-ride="carousel">
-
- <?php if ($this->options->JIndexCarousel) : ?>
- <?php
- $txt = $this->options->JIndexCarousel;
- $string_arr = explode("\r\n", $txt);
- $long = count($string_arr);
- ?>
- <div class="carousel-indicators">
- <?php
- for ($i = 0; $i < $long; $i++) {
- ?>
- <button type="button" data-bs-target="#banner" data-bs-slide-to="<?php echo $i ?>" class="active"></button>
- <?php } ?>
- </div>
- <div class="carousel-inner">
-
- <?php
- for ($i = 0; $i < $long; $i++) {
- $img = explode("||", $string_arr[$i])[0];
- $url = explode("||", $string_arr[$i])[1];
- $title = explode("||", $string_arr[$i])[2];
- ?> <div class="carousel-item active">
- <a class="banlist" href="<?php echo $url ?>">
- <img width="900" height="350" src="<?php echo $img ?>" class="attachment-900x350x1 size-900x350x1 wp-post-image" alt="" decoding="async" loading="lazy" /> <h2><?php echo $title ?></h2>
- </a> </div>
- <?php } ?>
- </div>
- <?php endif; ?>
-
- <button class="carousel-control-prev" type="button" data-bs-target="#banner" data-bs-slide="prev"><i class="bi bi-chevron-left"></i></button>
- <button class="carousel-control-next" type="button" data-bs-target="#banner" data-bs-slide="next"><i class="bi bi-chevron-right"></i></button>
- </div>
- </div>
复制代码
|