WordPress自定义评论列表
一、打开主题目录下的callback.php文件,加入以下代码
/**
*自定义评论列表
*/
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?>>
<article class="comment-body">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php echo get_avatar( $comment, $size = '36')?>
<b class="fn">
<?php echo get_comment_author_link();?>
<div class="comment-content"><?php comment_text(); ?></div>
</b>
</div>
<?php if ($comment->comment_approved == '0') : ?><em><?php _e('Your comment is awaiting moderation.') ?></em><br /><?php endif; ?>
<div class="comment-metadata">
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),' ','') ?>
</div>
</footer>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</article>
</li>
<?php
}
二、打开主题目录下的comments.php文件,把这段代码
<?php wp_list_comments( array( 'style' => 'ol', 'short_ping' => true, 'avatar_size' => 36, ) ); ?>
替换成:
<?php wp_list_comments('type=comment&callback=mytheme_comment'); ?>
或
<?php wp_list_comments('type=comment&amp;callback=mytheme_comment&amp;short_ping=true'); ?>
(此种代码还需要研究)
或者
<?php wp_list_comments( array( 'style' => 'ol', 'short_ping' => true, 'callback' => mytheme_comment, ) ); ?>
注意:
‘short_ping’ 的作用是:
1尝试通知文章中链接的博客
2允许其他博客发送链接通知(pingback和trackback)到新文章
把false改成true,这两项功能才能开启
tips:本文参考http://www.v7v3.com/themes_tag/2014061192.html
本主题涉及评论的文件:两个系统文件comment.php,comment-template.php;三个主题文件setup.php,comments.php,callback.php。
-
用is_mobile()函数判断手机设备wordpress
为了使得手机端和PC端显示不一样的内容字数,用了<?php if (is_mobile() ): ?>、<?php endif ;?>来判断,不过在此之前需要在 functions.php 内添加如下代码才能有效...
-
不变形原比例缩放图片代码
自己整理了几种图片展示的方法,实现图片原比例缩小、放大、不失真、不变形,先来看看实例图: 不变形原比例缩放图片代码 以下是对应的各种样式的代码。 <!DOCTYPE html> ...
-
给云存储绑定自定义域名
上一篇文章给网站开启CDN加速和云存储!简单介绍了CDN加速和云存储,本文着重介绍一下给云存储绑定自定义域名之后的加速和浏览器在线打开图片的设置。 当使用腾讯云存储对象V4创...
-
设计了一个网站…
近一段时间累的一塌糊涂也过的一塌糊涂,基本每天凌晨三五点睡,恨不得不用吃饭不用睡觉的敲代码,睡梦中还在php if 、else if 、div class…。虽然知道熬夜不好,但生怕一...
-
给网站开启CDN加速和云存储!
什么是CDN加速 相信很多站长朋友都在用wp-super-cache这款插件给自己的网站开启静态加速,它的原理是通过把网站生成静态页面缓存到本地,让访客直接浏览的是这个文件,而不需要...
长按或扫一扫,随意赞赏
共有 0 条评论