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。
-
设计了一个网站…
近一段时间累的一塌糊涂也过的一塌糊涂,基本每天凌晨三五点睡,恨不得不用吃饭不用睡觉的敲代码,睡梦中还在php if 、else if 、div class…。虽然知道熬夜不好,但生怕一...
-
增加文章目录toc功能并和.back-to-top同时出现
为了增加用户体验度,使得页面更加美观,我把文章目录嵌入.back-to-top层里,好处是不用再写script,直接引用.back-to-top的js功能,与“返回顶部”按钮在滚动条离顶部一定间距时...
-
给网站开启CDN加速和云存储!
什么是CDN加速 相信很多站长朋友都在用wp-super-cache这款插件给自己的网站开启静态加速,它的原理是通过把网站生成静态页面缓存到本地,让访客直接浏览的是这个文件,而不需要...
-
用is_mobile()函数判断手机设备wordpress
为了使得手机端和PC端显示不一样的内容字数,用了<?php if (is_mobile() ): ?>、<?php endif ;?>来判断,不过在此之前需要在 functions.php 内添加如下代码才能有效...
-
调用站内文章/文章内链短代码
昨天在大发的博客里看到他调用的站内文章样式很好看,高大上。随即给他留言向他请教,今天回复了一条教程链接,原来发哥早就写过教程,有需要的也可以看看,链接地址:https://f...
长按或扫一扫,随意赞赏
共有 0 条评论