typecho 附件页添加描述并加入sitemap.xml

  今天上班摸鱼时意外发现 Typecho 给每张附件图片也都有单独的页面(如:https://80srz.com/attachment/640/),顿时来了个莓用(没啥卵用)的想法,在图片文件页添加图片描述,并添加到 sitemap.xml 中。

莓用想法之科学解释

  1. 既然上传的图片有单独的前端展示页面,我们加上图片描述后,能够方便日后我们快速的回想起拍照时的感想、心情,再次触发心灵深处的那沉寂许久的小鹿,感觉对我们这种个人博客站长还是蛮有意义的;
  2. 添加到 sitemap 中,能够让你上传一张图片,在搜索引擎眼中,你又水了一篇文章,美滋滋……(有没有卵用,我也不知道!)
  3. 后面我还想做一个前端相册,但苦于根本不懂技术,没法搞,有大佬愿意的话,可以花几秒钟给整个……拜谢!

功能实现经过

研究分析

  花了几个世纪研究 https://80srz.com/attachment/640/ 页面代码及 typecho 系统文件、 数据表结构,还是被我这小白整明白了,不得不说 typecho 真真滴适合小白使用,总结为以下几点:

  1. 图片前端展示页用的是主题的 page.php 模板;
  2. 图片即(attachment)、页面(page)、文章(post) 共同存储在 typecho_contents 数据表中;type 分别是 attachmentpagepost ;
  3. BaiduSubmit 地图插件中由 Action.php 负责输出 sitemap.xml 数据;

修改 page.php 模板文件

  在 <?php parseContent($this); ?> 代码后面加上判断文件是否是图片,如是,则输出图片描述;不是就不输出内容;代码如下:

<?php if ($this->attachment->isImage): ?>
     <p><h3>“<?php $this->attachment->name();?>”的描述:</h3><br/><span style="padding-left:40px;"><?php $this->attachment->description();?></span></p>
<?php endif; ?>

DIY BaiduSubmit 地图插件

  声明:本人纯小白,BaiduSubmit 地图插件 DIY 过程就是看着代码是那么回事就复制,然后将字段改成 attachment ,还真能行!哈哈……谁都不服,就服我自己??

  以下是我对 BaiduSubmit 地图插件中 Action.php 文件 DIY 的几段代码:

52行:

$attachments = $db->fetchAll($db->select()->from('table.contents')
   ->where('table.contents.status = ?', 'publish')
   ->where('table.contents.created < ?', $options->gmtTime)
   ->where('table.contents.type = ?', 'attachment')
   ->order('table.contents.created', Typecho_Db::SORT_DESC));
            

84行:

foreach ($attachments AS $attachment) {
    $type = $attachment['type'];
    $routeExists = (NULL != Typecho_Router::get($type));
    $attachment['pathinfo'] = $routeExists ? Typecho_Router::url($type, $attachment) : '#';
    $urls[] = Typecho_Common::url($attachment['pathinfo'], $options->index);
}
        

142行:

$attachments = $db->fetchAll($db->select()->from('table.contents')
   ->where('table.contents.status = ?', 'publish')
   ->where('table.contents.created < ?', $options->gmtTime)
   ->where('table.contents.type = ?', 'attachment')
   ->order('table.contents.created', Typecho_Db::SORT_DESC));
            

230行:

foreach($attachments AS $attachment) {
        $type = $attachment['type'];
        $routeExists = (NULL != Typecho_Router::get($type));
        $attachment['pathinfo'] = $routeExists ? Typecho_Router::url($type, $attachment) : '#';
        $attachment['permalink'] = Typecho_Common::url($attachment['pathinfo'], $options->index);
        echo "\t<url>\n";
    echo "\t\t<loc>".$attachment['permalink']."</loc>\n";
    echo "\t\t<lastmod>".date('Y-m-d\TH:i:s\Z',$attachment['modified'])."</lastmod>\n";
    echo "\t\t<changefreq>monthly</changefreq>\n";
    echo "\t\t<priority>0.4</priority>\n";
    echo "\t</url>\n";
}    

注明:这里我将图片(文件)展示页权重设为 0.4 ,月更新 。可根据需要修改 230 行代码。

食用方法

步骤一:(参考前文)研究分析 → 修改 page.php 模板文件;

步骤二:安装《 BaiduSubmit 百度结构化插件魔改版之莓用版》 ,如果用的是“老高 & 迷你日志”的 BaiduSubmit 百度结构化插件魔改版 0.7 版 则直接覆盖上传即可。

  下载链接:https://pan.baidu.com/s/1G6vNrxcBs5S8euaM2EZq_Q

抱歉,隐藏内容 回复 后可见

前端相册(入口)以后折腾

  技术有限,冇法子,慢慢来。

效果

  1. 图片展示页:https://80srz.com/attachment/640/
  2. sitemap.php :https://80srz.com/sitemap.xml

免责声明

  我也不知道这么搞有没有啥卵用,会不会有啥反效果,反正就是玩呗,有感兴趣的朋友请慎用,由此造成的任何后果,本人不负责!!!

类似功能推荐:typecho给文章标签添加描述( description )字段
~ ~  本文结束,喜欢请点赞+分享  ~ ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
(*) 7 + 8 =
本文共 19 条评论。您也快来参与吧!
    1月24日 四川省 发自Android 回复 1

    看看

    2023年10月16日 河南省郑州市 发自Windows 10 回复 0

    看一看

    2023年09月30日 吉林省长春市 发自Linux 回复 0

    哈哈

    2023年08月02日 广东省深圳市 发自Mac OSX 回复 1

    看起来不错

    2023年05月21日 四川省成都市 发自Windows 10 回复 0

    小白学习来了

    2023年01月03日 美国加利福尼亚州洛杉矶 发自Windows 10 回复 0

    小白前来学习

      2023年01月03日 湖北省武汉市 发自Android 回复 0

      我也是小白

    2022年09月11日 广西梧州市 发自Iphone 回复 1

    小白前来学习

    2022年08月19日 美国华盛顿 发自Windows 10 回复 1

    来了来了

      2022年08月19日 台湾省台中市 发自Windows 10 回复 1
      该评论仅博主及评论双方可见!
        2022年08月19日 广东省广州市 发自Windows 10 回复 0
        该评论仅博主及评论双方可见!
    2022年07月12日 贵州省安顺市普定县 发自Windows 10 回复 0
    该评论仅博主及评论双方可见!
    2022年06月08日 河南省郑州市 发自Windows 10 回复 0

    6666666666