子比主题美化 – 热门推荐排行榜页面

子比主题美化 – 热门推荐排行榜页面-有道网创
子比主题美化 – 热门推荐排行榜页面
此内容为付费资源,请付费后查看
9.9
限时特惠
立即购买
您当前未登录!建议登陆后购买,可保存购买订单
付费资源
已售 77

核心代码

在主题的 func.php 中引入

//排行榜
function get_post_thumbnail_url($post_id) {
  $thumbnail_url = get_the_post_thumbnail_url($post_id, 'thumbnail');
  
  if (empty($thumbnail_url)) {
    $content = get_post_field('post_content', $post_id);
    
    if (strpos($content, '<img') !== false) {
      preg_match('/<img.+src=['"]([^'"]+)['"].*>/i', $content, $matches);
      
      if (!empty($matches[1])) {
        $thumbnail_url = $matches[1];
        
        // 验证缩略图URL是否有效
        if (!filter_var($thumbnail_url, FILTER_VALIDATE_URL)) {
          $thumbnail_url = '';
        }
      }
    }
  }
  
  return $thumbnail_url;
}

引入区块

主题目录下的 index.php 中引入以下代码,放置于 <?php get_footer(); 前

<?php
if (file_exists(get_theme_file_path('/Index_rankinglist.php'))) {
    require_once get_theme_file_path('/Index_rankinglist.php');
}
?>

引入JS

<script type='text/javascript' src='https://huliku.com/huliku/js/ranking.js'></script>

上传文件放置于主题目录下即可

------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明

THE END
喜欢就支持一下吧
点赞9 分享