[教程] 给typecho添加一个轮播图

查看: 519|回复: 1
crll 发表于 2023-4-4 10:59:02
代码来自joe主题~
functions.php添加:
  1.     $JIndexCarousel = new Typecho_Widget_Helper_Form_Element_Textarea(
  2.         'JIndexCarousel',
  3.         NULL,
  4.         NULL,
  5.         '首页轮播图',
  6.         '介绍:用于显示首页轮播图,请务必填写正确的格式 <br />
  7.          格式:图片地址 || 跳转链接 || 标题 (中间使用两个竖杠分隔)<br />
  8.          其他:一行一个,一行代表一个轮播图 <br />
  9.          例如:<br />
  10.             https://puui.qpic.cn/media_img/lena/PICykqaoi_580_1680/0 || http://baidu.com || 百度一下 <br />
  11.             https://puui.qpic.cn/tv/0/1223447268_1680580/0 || http://v.qq.com || 腾讯视频
  12.          '
  13.     );
  14.     $JIndexCarousel->setAttribute('class', 'col-mb-12 typecho-option setc');
  15.     $form->addInput($JIndexCarousel);
复制代码


调用~
  1.     <div class="container">
  2.          <div id="banner" class="carousel slide" data-bs-ride="carousel">
  3.             
  4.                          <?php if ($this->options->JIndexCarousel) : ?>
  5.             <?php
  6.             $txt = $this->options->JIndexCarousel;
  7.             $string_arr = explode("\r\n", $txt);
  8.             $long = count($string_arr);
  9.             ?>               
  10.                         <div class="carousel-indicators">
  11.                         <?php
  12.                     for ($i = 0; $i < $long; $i++) {
  13.                     ?>
  14.                                     <button type="button" data-bs-target="#banner" data-bs-slide-to="<?php echo $i ?>" class="active"></button>
  15.                         <?php } ?>   
  16.                                                         </div>               
  17.             <div class="carousel-inner">
  18.                                  
  19.                                          <?php
  20.                     for ($i = 0; $i < $long; $i++) {
  21.                         $img = explode("||", $string_arr[$i])[0];
  22.                         $url = explode("||", $string_arr[$i])[1];
  23.                         $title = explode("||", $string_arr[$i])[2];
  24.                     ?>                  <div class="carousel-item active">               
  25.                         <a class="banlist" href="<?php echo $url ?>">
  26.                             <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>
  27.                         </a> </div>
  28.                                                 <?php } ?>
  29.                    </div>
  30.                                         <?php endif; ?>
  31.                            
  32.             <button class="carousel-control-prev" type="button" data-bs-target="#banner" data-bs-slide="prev"><i class="bi bi-chevron-left"></i></button>
  33.             <button class="carousel-control-next" type="button" data-bs-target="#banner" data-bs-slide="next"><i class="bi bi-chevron-right"></i></button>
  34.         </div>
  35.     </div>
复制代码
博主论坛 bzlt.net
叶开 发表于 2023-4-4 12:30:13
收藏了!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于本站联系我们FAQ友情链接免责声明生存法则

Build with for "make" Copyright © 2020-2022. Powered by Discuz! GMT+8, 2024-5-19 06:54

快速回复 返回顶部 返回列表