wordpress教程之wp list comments

作者:  耕堂 | 本文浏览1483次 | 2009年08月11日

wordpress模板标签/wp list comments
-描述:
显示文章或页面的评论。
-使用:

<?php wp_list_comments( $args ); ?>

-默认使用:

<?php $args = array(‘walker’ => null,

‘max_depth’ => ,

’style’ => ‘ul’,

‘callback’ => null,

‘end-callback’ => null,

‘type’ => ‘all’,

‘page’ => ,

‘per_page’ => ,

‘avatar_size’ => 32,

‘reverse_top_level’ => null,

‘reverse_children’ => ); ?>

cc

  • avatar_size
  • (整数)显示的头像像素大小,默认为32,http://gravatar.com/ 支持从1到512。

  • style
  • (字符串)可以为‘div’、‘ol’或‘ul’,各自代表容器,有序列表或无序列表。默认为ul。若有包含标签时必须明确写出:

    <div class=”commentlist”><?php wp_list_comments(array(’style’ => ‘div’)); ?></div>或

    <ol class=”commentlist”><?php wp_list_comments(array(’style’ => ‘ol’)); ?></ol>

  • type
  • (字符串)要显示评论的类型,可以是’all’, ‘comment’, ‘trackback’, ‘pingback’, 或 ‘pings’。 ‘pings’ 既包括 ‘trackback’ 也包括 ‘pingback’ 。默认都显示(即all)。

  • reply_text
  • (字符串)每个评论中作为回复链接的文本(它不是wp_list_comments的参数,但可以通过函数get_comment_reply_link实现)。默认为’reply‘。

  • login_text
  • (字符串)如果使用者必须注册并登陆才能评论的文本(它不是wp_list_comments的参数,但可以通过函数get_comment_reply_link实现)。默认为’Log in to Reply‘。

  • callback
  • (字符串)用于显示每条评论的自定义函数的名字(不推荐使用)。
    -例子:
    1.默认使用

    <ol class=”commentlist”><?php wp_list_comments(); ?>

    </ol>

    2.用自定义callback函数控制评论外观,只显示评论(非pingbacks或trackbacks)。若回复链接不出现时,可以加一个max_depth=x参数。

    <ul class=”commentlist”><?php wp_list_comments(‘type=comment&callback=mytheme_comment’); ?>

    </ul>

    需要在functions.php中自定义callback函数,如下例:

    function mytheme_comment($comment, $args, $depth) {$GLOBALS['comment'] = $comment; ?>

    <li <?php comment_class(); ?> id=”li-comment-<?php comment_ID() ?>”>

    <div id=”comment-<?php comment_ID(); ?>”>

    <div class=”comment-author vcard”>

    <?php echo get_avatar($comment,$size=’48′,$default=’<path_to_url>’ ); ?>
    <?php printf(__(‘<cite class=”fn”>%s</cite> <span class=”says”

    >says:</span>’), get_comment_author_link()) ?>

    </div>

    <?php if ($comment->comment_approved == ‘0′) : ?>

    <em><?php _e(‘Your comment is awaiting moderation.’) ?></em>

    <br />

    <?php endif; ?>

    <div class=”comment-meta commentmetadata”><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>

    <?php comment_text() ?>

    <div class=”reply”>

    <?php comment_reply_link(array_merge( $args, array(‘depth’ => $depth, ‘max_depth’ =>

    $args['max_depth']))) ?>

    </div>

    </div>

    <?php

    }

    注意:上面代码缺了</li>,当它运行时wordpress会自动加上。
    这里有英文原版文档

     右上方更多相关内容/站内搜索-关键词请用空格隔开

  • 标签 :  , , , ,
  • 原文链接 : http://www.gengtang.net/wordpress/wp-list-comments.html
  • 转载原创文章请注明 : 耕堂-gengtang.net
  •  “wordpress教程之wp list comments” 有3条评论

    1. 2009年9月2日的8:01 下午,传说中的 Elcorin

      I have already seen it somethere…

    2. 2009年9月2日的8:35 下午,传说中的 耕堂

      Maybe, I just translate it form wordpress.org ^-^

    发表留言

    可用HTML标签:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>