让文章只显示摘要

打开主题目录,找到 index.phparchive.php 两个文件,将原有的代码

        <div class="post-content" itemprop="articleBody">
            <?php $this->content('- 阅读剩余部分 -'); ?>                   
        </div>

替换成

        <div class="post-content" itemprop="articleBody">
            <?php if($this->options->summaryNum):  ?>
                <?php $this->excerpt($this->options->summaryNum, ''); ?>
            <?php else:?>
                <?php $this->excerpt(140, ''); ?>
            <?php endif; ?>
            <a itemprop="url" href="<?php $this->permalink() ?>"> 阅读剩余部分...</a>
        </div>

博客添加favicon

将favicon.ico文件上传到主题目录,然后打开 header.php 文件,在head区域添加如下代码:

<?php if($this->options->icoPath):  ?>
    <link rel="shortcut icon" href="<?php $this->options->icoPath(); ?>" type="image/x-icon" />
<?php else: ?>
    <link rel="shortcut icon" href="/usr/themes/memoo/favicon.ico" type="image/x-icon" />
<?php endif ?>

文章页添加编辑按钮,仅登录可见

index.php 中,找到 评论,在其后方添加如下代码: 在 post.php 中,找到 分类,在其后方同样添加如下代码:

    <?php if($this->user->hasLogin()): ?>
         <a href="<?php $this->options->adminUrl('write-post.php?cid=' . $this->cid); ?>">编辑</a>
    <?php endif; ?>

文章显示阅读量

首先装 ViewsCounter 插件,插件获取地址:Typecho-ViewsCounter。插件安装完成后,复制以下代码:

        <li> 
           <?php echo ViewsCounter_Plugin::getViews(); ?> 阅读
        </li>

将其粘贴到想要展示的位置即可。我想在博客首页和文章详情页展示,那么就需要更改 index.phppost.php 两个文件。只需要将以上代码粘贴到文章发布时间之后就行了。

文章显示目录

默认的文本编辑器。虽支持MarkDown,但不支持 [TOC] 命令,需要安装 MarkdownParse 插件,下载地址是typecho-markdown,由于最新版只支持php8.1及以上的版本,因此我选择了3.0版本进行安装。

代码行显示

安装 CodeStyle 插件,下载地址为 CodeStyle

右侧标签云

sidebar.php文件中 其它 位置处上方,添加如下代码:

 <section class="widget">
  <h3 class="widget-title"><?php _e('标签'); ?></h3>
  <ul class="widget-list" style="display: flex; flex-wrap: wrap; padding: 0; list-style: none;">
  <?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=28')->to($tags); ?>
  <?php while($tags->next()): ?>
        <li style="margin-right: 10px;"><a href="<?php $tags->permalink(); ?>" class="size-<?php $tags->split(5, 10, 20, 30); ?>"><?php $tags->name(); ?></a></li>
  <?php endwhile; ?>
  </ul>

页面逻辑重构

由于文章只有我一个人发布,因此没必要显示作者,所以在index和post两个php文件中,删除显示作者相关代码。 由于文章分类在首页显示,当点进去后,没必要再在标题附近显示,可以将分类和标签添加在底部。 网站右侧,不需要评论RSS和Typecho的网址,因此可以直接删除掉。

侧边栏分类添加计数功能

将主题文件夹下的sidebar.php文件中,将原有代码

<?php \Widget\Metas\Category\Rows::alloc()->listCategories('wrapClass=widget-list'); ?>

替换为如下代码:

<?php $this->widget('Widget_Metas_Category_List')->listCategories('wrapClass=widget-list&showCount=1&countTemplate=<span>(%d)</span>'); ?>

本文链接:博客主题更改记录 - https://soft.cry33.com/archives/7.html

版权声明:原创文章 遵循 CC 4.0 BY-SA 版权协议,转载请附上原文链接和本声明。

分类:默认分类

标签:none

添加新评论