OriginalTechnology
# handsome # Code # Code life

Delete the picture description of the handsome album article

1,382 words3 minute52 views0 likes

Summary

This article introduces how to delete image descriptions in album articles in the Handsome theme. When users upload pictures, they find that the pictures contain description information, which affects the browsing experience. By modifying the TypePost.php file in the theme directory, replacing the relevant code, and removing the alt attribute of the image, only the image will be displayed without the description on the album page. This operation is simple and effective. It is recommended to back up the original files. After the modification, the picture display is more concise and the visual problem is solved.

The reason is that when I wanted to upload my photo album to the photo album page in the handsome theme, except for some problems, the pictures I uploaded all had descriptions, which made my eyes very uncomfortable

Before modification

请输入图片描述

modified

请输入图片描述

finally saved my eyes

Modification method

Open the directory /usr/themes/handsome/libs/content/

Find the TypePost.php file, copy all the following code, replace it, and make a backup! ! !

<?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>";
        }
    }
}
Loading comments…
Related articles

Related articles