主题更改文章自定义随机封面

发布于 2024-08-21  71 次阅读


Puock主题更改function.php

            $folder_path = '/www/wwwroot/wordpress/wp-content/themes/kratos-pjax-master/static/images/thumb/';  // 替换为实际的本地文件夹路径
            $hots_url = substr(get_template_directory_uri(), 0, strpos(get_template_directory_uri(), '/wp-')?: strlen(get_template_directory_uri()));
            if (is_dir($folder_path)) {
              $file_list = scandir($folder_path);     
              $file_count = count($file_list) - 2;  // 减去 '.' 和 '..'
              $random = mt_rand(1, $file_count);
              $res = $hots_url . '/wp-content/themes/kratos-pjax-master/static/images/thumb/thumb_' . $random . '.jpg';
            } else {
              $random = mt_rand(1,20);
              $res = $hots_url . '/wp-content/themes/kratos-pjax-master/static/images/thumb/thumb_' . $random . '.jpg';
            }    
        
    }

  • alipay_img
  • wechat_img
个人信息
最后更新于 2024-08-30