요약
이 글에서는 핸썸 테마의 앨범 글에 있는 이미지 설명을 삭제하는 방법을 소개합니다. 사용자가 사진을 업로드하면 사진에 탐색 경험에 영향을 미치는 설명 정보가 포함되어 있음을 알게 됩니다. 테마 디렉토리에 있는 TypePost.php 파일을 수정하고, 해당 코드를 교체하고, 이미지의 alt 속성을 제거하면 앨범 페이지에 설명 없이 이미지만 표시됩니다. 이 작업은 간단하고 효과적입니다. 원본 파일을 백업하는 것이 좋습니다. 수정 후 사진 표시가 더욱 간결해지고 시각적 문제가 해결되었습니다.
그 이유는 잘생긴 테마로 사진첩 페이지에 사진집을 올리려고 했을 때 몇 가지 문제를 제외하면 제가 올린 사진들 모두 설명이 있어서 눈이 많이 불편했거든요
수정 전

수정됨

드디어 내 눈을 구했다
수정 방법
/usr/themes/handsome/libs/content/
디렉터리를 엽니다.
<?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>";
}
}
}











