博主

昨天 16:14在线

秃头张
保护好自己的头发
博主 秃头张
博主 昨天 16:14 在线自豪地使用 Typecho 建站搭配使用 🌻Sunny 主题当前在线 1 人
歌曲封面 未知作品

网站已运行 1 年 257 天 6 小时 28 分

Powered by Typecho & Sunny

2 online · 16 ms

Title

删除handsome相册文章的图片描述

秃头张

·

技术

·

Article
起因是我想把自己的相册上传到handsome主题中的相册页面的时候除了点问题,我上传的图片都是有描述的,这导致我的眼睛很受不了

修改前

请输入图片描述

修改后

请输入图片描述

终于是拯救了我的眼睛啊

修改方法

打开目录/usr/themes/handsome/libs/content/

找到TypePost.php文件,将下面的代码全部复制,进行替换,注意做好备份!!!

♾️ text 代码:
<?php
/**
 * 多种不同的文章内容,目前支持相册和普通文章两种,有计划支持视频类型
 */

class TypePost{

    /**
     * @param $content
     * @param $obj
     * @return string
     */
    public static function postImagePost($content, $obj)
    {
        if ($obj->hidden === true) {//输入密码访问
            return $content;
        } else {
            return TypePost::parseContentToImage($content, "album");
        }
    }

    /**
     * 解析文章内容为图片列表(相册)
     * @param $content
     * @param $type
     * @return string
     */
    public static function parseContentToImage($content, $type)
    {
        preg_match_all('/<img.*?src="(.*?)"(.*?)(alt="(.*?)")??(.*?)\/?>/', $content, $matches);

        if (is_array($matches) && count($matches[0]) > 0) {

            $html = "";
            if ($type === "photos") {//自适应拉伸的
                $html .= "<div class='album-photos'>";
            } else {//统一宽度排列
                $html .= "<div class='photos'>";
            }
            for ($i = 0; $i < count($matches[0]); $i++) {
                $info = trim($matches[5][$i]);
                preg_match('/alt="(.*?)"/', $info, $info);
                if (is_array($info) && count($info) >= 2) {
                    $info = @$info[1];
                } else {
                    $info = "";
                }
                if ($type == "photos") {
                    $html .= <<<EOF
<figure>
        {$matches[0][$i]}
</figure>
EOF;
                } else {
                    $html .= <<<EOF
<figure class="image-thumb" itemprop="associatedMedia" itemscope="" itemtype="http://schema.org/ImageObject">
          {$matches[0][$i]}
      </figure>
EOF;
                }
            }

            $html .= "</div>";

            return $html;
        } else {
            //解析失败,就不解析,交给前端进行解析,还原之前的短代码
            $type = ($type == "photos") ? ' type="photos"' : "";
            return "<div class='album_block'>\n\n[album" . $type . "]\n" . $content . "[/album] </div>";
        }
    }
}
现在已有 233 次阅读,7 条评论,0 人点赞
Author:秃头张
作者
删除handsome相册文章的图片描述
当前文章累计共 2394 字,阅读大概需要 1 分钟。
免费资源网采集规则-教程
2024年10月30日 · 5评论
快科技采集规则-所有栏目
2024年11月4日 · 2评论
醉美宜宾,我来啦
2024年6月5日 · 0评论
请手动关闭typecho评论设置中的“开启反垃圾保护”复选框
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主 不再显示
博主