博主

19秒前在线

秃头张
保护好自己的头发
歌曲封面 未知作品

网站已运行 1 年 220 天 14 小时 6 分

Powered by Typecho & Sunny

3 online · 19 ms

Title

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

秃头张

·

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

修改前

请输入图片描述

修改后

请输入图片描述

[scode type="green" size=""]

终于是拯救了我的眼睛啊

[/scode]

修改方法

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

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

[hide]

♾️ 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>";
        }
    }
}

[/hide]

现在已有 98 次阅读,4 条评论,0 人点赞
Comment:共4条
发表
  1. 头像
    @
    王莉
    终于解决了相册图片描述的问题,眼睛终于能休息一下了!感谢分享这个解决方法,简直是拯救了我的视觉体验。
    · iPhone · Safari · 本机地址

    👍

    💖

    💯

    💦

    😄

    🪙

    👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
  2. 头像
    @

    博主

    秃头张
    这篇文章介绍了如何删除handsome主题相册中的图片描述。通过修改TypePost.php文件中的代码,可以去除上传相册时自动生成的图片描述,从而让页面更加简洁,避免视觉上的干扰。
    · MacOS · Chrome · 本机地址

    👍

    💖

    💯

    💦

    😄

    🪙

    👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
  3. 头像
    @
    晚上好,回踩回踩回踩来啦。 ::aru:shy2::
    · Windows · Chrome · 中国湖北省移动

    👍

    💖

    💯

    💦

    😄

    🪙

    👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
    1. 头像
      @
      观望大佬
      · MacOS · Chrome · 美国华盛顿Cogent通信公司

      👍

      💖

      💯

      💦

      😄

      🪙

      👍 0 💖 0 💯 0 💦 0 😄 0 🪙 0
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主 不再显示
博主