返回列表 发布新帖
查看: 122|回复: 1

[代码技巧] 子比主题二次元风格热门文章排行榜

[复制链接]
SunJu_FaceMall
#网站认证# 飞流网创始人  网站认证

飞流网创始人

社区贡献

102

主题

173

回帖

1万

积分

等级头衔
Icon组别 : 管理员
Icon等级 :

积分成就
   钻石 : 49 颗
   贡献 : 364 点
   金币 : 9 枚
Icon在线时间 : 1136 小时
Icon注册时间 : 2024-11-22
Icon最后登录 : 2025-9-19

荣誉勋章

会员LV.1会员LV.2会员LV.3会员LV.4会员LV.5会员LV.6会员LV.7会员LV.8会员LV.9会员LV.10

资源无需等待,交易就趁现在,全面资源整合网络大咖云集,让你轻松玩转互联网!

您需要 登录 才可以下载或查看,没有账号?立即注册

×
刚玩子比的时候就看到很多新鲜的排行榜,最近感觉和我想得略微有些差距,让ai帮我搞了搞,今天分享给大家。
效果演示
1000221407.webp
代码
<?php
  • Zib_CFSwidget::create('widget_rank', array(
  •     'title'       => 'top-热门排行榜',
  •     'zib_title'   => true,
  •     'zib_affix'   => true,
  •     'zib_show'    => true,
  •     'description' => '二次元风格热门文章排行榜',
  •     'fields'      => array(
  •         array('title' => '排行榜1名称', 'id' => 'hot_1', 'type' => 'text', 'default' => '建站资源'),
  •         array('title' => '排行榜1分类ID', 'id' => 'hot_1_cat', 'type' => 'text', 'default' => '1'),
  •         array('title' => '排行榜1显示个数', 'id' => 'hot_1_num', 'type' => 'text', 'default' => '5'),
  •         array('title' => '排行榜1跳转文字', 'id' => 'hot_1_link_text', 'type' => 'text', 'default' => '更多'),
  •         array('title' => '排行榜1跳转链接', 'id' => 'hot_1_link', 'type' => 'text', 'default' => '/hot'),

  •         array('title' => '排行榜2名称', 'id' => 'hot_2', 'type' => 'text', 'default' => '子比美化'),
  •         array('title' => '排行榜2分类ID', 'id' => 'hot_2_cat', 'type' => 'text', 'default' => '1'),
  •         array('title' => '排行榜2显示个数', 'id' => 'hot_2_num', 'type' => 'text', 'default' => '5'),
  •         array('title' => '排行榜2跳转文字', 'id' => 'hot_2_link_text', 'type' => 'text', 'default' => '更多'),
  •         array('title' => '排行榜2跳转链接', 'id' => 'hot_2_link', 'type' => 'text', 'default' => '/hot'),

  •         array('title' => '排行榜3名称', 'id' => 'hot_3', 'type' => 'text', 'default' => '软件基地'),
  •         array('title' => '排行榜3分类ID', 'id' => 'hot_3_cat', 'type' => 'text', 'default' => '1'),
  •         array('title' => '排行榜3显示个数', 'id' => 'hot_3_num', 'type' => 'text', 'default' => '5'),
  •         array('title' => '排行榜3跳转文字', 'id' => 'hot_3_link_text', 'type' => 'text', 'default' => '更多'),
  •         array('title' => '排行榜3跳转链接', 'id' => 'hot_3_link', 'type' => 'text', 'default' => '/hot'),
  •     )
  • ));

  • function widget_rank($args, $instance)
  • {
  •     Zib_CFSwidget::echo_before($instance, '');
  •     ?>
  •     <style>
  •         .rank-container {
  •             display: grid;
  •             grid-template-columns: repeat(3, 1fr);
  •             gap: 20px;
  •             margin-bottom: 15px; /* 小工具底部空隙 */
  •         }
  •         @media (max-width: 1024px) {
  •             .rank-container {
  •                 grid-template-columns: repeat(2, 1fr);
  •             }
  •         }
  •         @media (max-width: 768px) {
  •             .rank-container {
  •                 grid-template-columns: 1fr;
  •             }
  •         }
  •         .rank-block {
  •             position: relative;
  •             background: var(--main-bg-color);
  •             border-radius: 14px;
  •             box-shadow: 0 6px 14px rgba(0,0,0,0.08);
  •             overflow: hidden;
  •             transition: transform 0.25s ease;
  •         }
  •         .rank-block:hover {
  •             transform: translateY(-6px) scale(1.02);
  •         }
  •         .rank-header {
  •             background: linear-gradient(135deg, #ff9de6, #9dd9ff);
  •             color: #fff;
  •             padding: 12px 16px;
  •             font-weight: bold;
  •             font-size: 16px;
  •             display: flex;
  •             align-items: center;
  •             gap: 8px;
  •         }
  •         .rank-header::before {
  •             content: "★";
  •             font-size: 18px;
  •         }
  •         .rank-list {
  •             display: flex;
  •             flex-direction: column;
  •         }
  •         .rank-item {
  •             display: flex;
  •             align-items: center;
  •             gap: 12px;
  •             padding: 10px 14px;
  •             border-bottom: 1px dashed #f3c2ff;
  •             text-decoration: none;
  •             color: #444;
  •             transition: background 0.2s ease, transform 0.2s ease;
  •         }
  •         .rank-item:hover {
  •             background: rgba(255, 237, 255, 0.4);
  •             transform: translateX(4px);
  •         }
  •         .rank-num {
  •             flex-shrink: 0;
  •             width: 26px;
  •             height: 26px;
  •             border-radius: 50%;
  •             background: #ccc;
  •             color: #fff;
  •             display: flex;
  •             align-items: center;
  •             justify-content: center;
  •             font-size: 13px;
  •             font-weight: bold;
  •         }
  •         .rank-num.top1 { background: linear-gradient(135deg, #ff5f6d, #ffc371); }
  •         .rank-num.top2 { background: linear-gradient(135deg, #42e695, #3bb2b8); }
  •         .rank-num.top3 { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }
  •         .rank-thumb {
  •             flex-shrink: 0;
  •             width: 48px;
  •             height: 48px;
  •             border-radius: 10px;
  •             overflow: hidden;
  •             box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  •         }
  •         .rank-thumb img {
  •             width: 100%;
  •             height: 100%;
  •             object-fit: cover;
  •         }
  •         .rank-info {
  •             flex: 1;
  •         }
  •         .rank-title {
  •             font-size: 14px;
  •             font-weight: 600;
  •             margin-bottom: 4px;
  •             line-height: 1.3;
  •             color: var(--key-color);
  •         }
  •         .rank-meta {
  •             font-size: 12px;
  •             color: var(--muted-color);
  •         }
  •         .rank-footer {
  •             text-align: center;
  •             padding: 10px;
  •             background: rgba(255, 237, 255, 0.5);
  •         }
  •         .rank-footer a {
  •             font-size: 14px;
  •             color: #ff6bb5;
  •             text-decoration: none;
  •             font-weight: bold;
  •         }
  •         .rank-footer a:hover {
  •             text-decoration: underline;
  •         }
  •     </style>

  •     <div class="rank-container">
  •         <?php for ($i = 1; $i <= 3; $i++): ?>
  •             <?php
  •                 $title = $instance["hot_{$i}"];
  •                 $cat_id = $instance["hot_{$i}_cat"];
  •                 $num = $instance["hot_{$i}_num"];
  •                 $link_text = $instance["hot_{$i}_link_text"];
  •                 $link = $instance["hot_{$i}_link"];
  •                 $phnum = 0;
  •             ?>
  •             <div class="rank-block">
  •                 <div class="rank-header"><?php echo esc_html($title); ?></div>
  •                 <div class="rank-list">
  •                     <?php
  •                     $args_query = array(
  •                         'cat' => $cat_id,
  •                         'showposts' => $num,
  •                         'orderby' => 'meta_value_num',
  •                         'meta_key' => 'views',
  •                         'order' => 'DESC'
  •                     );
  •                     query_posts($args_query);
  •                     while (have_posts()) : the_post(); $phnum++;
  •                     ?>
  •                         <a class="rank-item" href="<?php the_permalink(); ?>" target="_blank" rel="nofollow">
  •                             <div class="rank-num <?php echo $phnum <= 3 ? 'top'.$phnum : ''; ?>"><?php echo $phnum; ?></div>
  •                             <div class="rank-thumb"><?php echo zib_post_thumbnail('', 'thumbnail'); ?></div>
  •                             <div class="rank-info">
  •                                 <div class="rank-title"><?php the_title(); ?></div>
  •                                 <div class="rank-meta"><?php echo get_post_view_count('', ''); ?> 热度</div>
  •                             </div>
  •                         </a>
  •                     <?php endwhile; wp_reset_query(); ?>
  •                 </div>
  •                 <?php if (!empty($link) && !empty($link_text)): ?>
  •                     <div class="rank-footer"><a href="<?php echo esc_url($link); ?>" target="_blank" rel="nofollow"><?php echo esc_html($link_text); ?></a></div>
  •                 <?php endif; ?>
  •             </div>
  •         <?php endfor; ?>
  •     </div>
  •     <?php
  •     Zib_CFSwidget::echo_after($instance);
  • }
  • ?>

  • 使用教程
    在zibll主题文件下新建一个.php的文件,将上面的代码粘贴在新建的文件中,然后新建func.php
    将下面的代码写入到func.php中
    <?php
  • if (file_exists(get_theme_file_path('/文件名.php'))) {
  •     require_once get_theme_file_path('/文件名.php');
  • }
  • 路虽远,行则将至;事虽难,做则必成。
    社区贡献

    3

    主题

    2

    回帖

    921

    积分

    等级头衔
    Icon组别 : 星辰会员
    Icon等级 :

    积分成就
       钻石 : 0 颗
       贡献 : 182 点
       金币 : 0 枚
    Icon在线时间 : 31 小时
    Icon注册时间 : 2025-6-30
    Icon最后登录 : 2025-9-19

    荣誉勋章
    司磐
    UID:10973
    暂无靓号,点击前往开通
    vip 发表于 2025-9-4 10:47:00 飞流灵通APP | 查看全部 四川阿坝州
    敢问大佬,真的没有创作瓶颈嘛~
    诚信连接交易,资源创造价值。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    飞流广播+ 发布

    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    09-11 11:40
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    09-02 09:17
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    08-27 08:56
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    08-20 15:12
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    08-03 10:22
    系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
    06-30 08:57
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    06-18 09:14
    系统消息:清风网络已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
    04-11 09:40
    系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    04-10 09:31
    系统消息:IXM77777已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    04-09 13:44
    系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    04-09 09:22
    系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
    04-09 08:52
    系统消息:清风网络已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    04-08 09:24
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    04-07 09:02
    系统消息:柒沐已经连续答对10道难题,逆天学霸谁与争锋?!#每日答题#
    02-27 09:35
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    02-26 09:06
    系统消息:柒沐已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    02-25 08:49
    系统消息:飞流安卓客户端APP已上线,请在QQ群(123129)群文件内获取下载。
    02-21 02:22
    系统消息:四哥已经连续答对3道难题,逆天学霸谁与争锋?!#每日答题#
    12-14 12:55
    01-24 12:40
    站内通告

    提供资源交易、信息共享、靓号交流、技术变现、学习问答、兴趣娱乐等全面服务。

    1.丰富功能系统,扩展社区特色玩法,打造最好的互联网聚集圈子。

    2.准确信息真实交易,安全快捷又方便,让虚拟交易面对面。

    3. 天上不会掉馅饼,话术骗术迷人心,切勿脱离平台线下交易,被骗与平台无关!

    4. 欺诈骗钱,违规违法将视情受到警告&禁言&封号甚至检举至👮🏻‍♀️处理!

    官方Q群:123129钉推群:BAYR2383 站长QQ:3220000000

    投诉/建议/商务合作联系

    fl@fllt.cn

    严禁私下交易,被骗与本站无关。
    违反交易细则,取证立查严惩。
    • 钉钉新帖推送群
    • 官方交流QQ群
    • 站长唯一微信号

    👮曝光Ta|🧿小黑屋|📴手机页|飞流网 ( 渝ICP备2025054677号-1|电信增值许可 渝B2-20250789 )|网站地图

    GMT+8, 2025-9-19 02:57 , Processed in 0.081996 second(s), 74 queries, MemCached On , Gzip On.

    Based on XJ-TX X3.5 Licensed

    飞流论坛 HanAnalytics icp Astro vhAstro-Theme

    关灯 在本版发帖
    扫一扫添加微信客服
    QQ客服返回顶部
    快速回复 返回顶部 返回列表