Typecho 的评论显示区默认是访客评论和引用通告放在一块区域的,这种显示方式可能很多人不喜欢,博客吧也不喜欢,因为堆在一块会显得很混乱,毕竟引用通告的样式和评论的样式是有差异的,博客吧当前的主题模板也是把评论区域和引用通告域名分隔开来的。下面引自Typecho官方相关代码介绍下分享文章评论和引用通告。
Typecho 控制评论的类型的代码:
- 显示全部(默认),即显示comment、trackback、pingback
<?php $this->comments()->to($comments); ?> |
- 只显示comment
<?php $this→comments('comment')→to($comments); ?> |
- 只显示trackback
<?php $this→comments('trackback')→to($trackbacks); ?> |
- 只显示pingback
<?php $this→comments('pingback')→to($pingbacks); ?> |
Typecho 分享文章评论和引用通告:
- 对主题模板 comments.php 文件进行编辑操作,在其中找到显示全部的语句,然后对其进行修改,也就是把显示全部的语句换成只显示评论:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| <?php $this->comments('comment')->to($comments); ?><!-- 关键 -->
<?php if ($comments->have()) : ?>
<ol>
<?php while ($comments->next()) : ?>
<li id="<?php $comments->theId() ?>">
<div class="comment_data">
<?php $comments->gravatar(32, '', '', 'avatar'); ?>
<span><?php $comments->author() ?></span> Says:<br />
<?php $comments->date('F jS, Y'); ?> at <?php $comments->date('h:i a'); ?>
</div>
<div class="comment_text"><?php $comments->content() ?></div>
</li>
<?php endwhile; ?>
</ol>
<?php endif; ?> |
- 然后输出 pingback,pingback 并不需要那么多的展示内容,假设只展示标题和日期,则修改代码如下
1
2
3
4
5
6
7
8
9
10
11
| <?php $this->comments('pingback')->to($pingbacks); ?><!-- 关键 -->
<?php if ($pingbacks->have()) : ?>
<h3>Pingbacks</h3>
<ol>
<?php while ($pingbacks->next()) : ?>
<li id="<?php $pingbacks->theId() ?>">
<?php $pingbacks->author() ?> <?php $pingbacks->date('F jS, Y'); ?>
</li>
<?php endwhile; ?>
</ol>
<?php endif; ?> |
- 把输出 pingback 的代码与输出评论的代码放在不同的位置即可。也可以分别为它们添加CSS样式。
同理,如果要显示 trackback,可按如上的修改方法
历史资源提醒--必看
该页面资源/教程来自原魔趣吧历史资源转移,因发布历史久远,部分资源/教程可能已失效或无法在最新版程序中安装使用!DZ资源建议在Discuz3.4及以下版本使用,PHP版本建议5.6。资源仅提供做代码研究学习使用!
因改版,部分贴内链接将无法正常跳转,如链接失效或未正常跳转,请利用站内搜索功能搜索资源名称获取对应资源!