Nid*_*ida 1 wordpress wordpress-theming wordpress-plugin
嗨我已经通过我的模板文件中的自定义代码检索了注释,如下所示
<?php $comments = get_comments();?>
<?php foreach($comments as $comment) : ?>
<?php if ($comment->comment_approved == '0') : ?>
<p class="waiting-message">Your comment is awaiting moderation.</p>
<?php endif; ?>
<?php echo $comment->comment_author; ?>
<?php echo comment_date('n M y'); ?>
<?php echo $comment->comment_content;?>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
现在我不知道怎么做编号分页如<< 1,2,3 >> ...请帮帮我
define('DEFAULT_COMMENTS_PER_PAGE',5);
$id=get_the_ID();
$page = (get_query_var('page')) ? get_query_var('page') : 1;;
//$page=2;
$limit = DEFAULT_COMMENTS_PER_PAGE;
$offset = ($page * $limit) - $limit;
$param = array(
'status'=>'approve',
'offset'=>$offset,
'post_id'=>$id,
'number'=>$limit,
);
$total_comments = get_comments(array('orderby' => 'post_date' ,
'order' => 'DESC',
'post_id'=>$id,
'status' => 'approve',
'parent'=>0));
$pages = ceil(count($total_comments)/DEFAULT_COMMENTS_PER_PAGE);
$comments = get_comments($param );
Run Code Online (Sandbox Code Playgroud)
你的评论会是这样的
和分页一样
<?php
$args = array(
'base' => @add_query_arg('page','%#%'),
'format' => '?page=%#%',
'total' => $pages,
'current' => $page,
'show_all' => False,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => True,
'prev_text' => __('Previous'),
'next_text' => __('Next'),
'type' => 'plain');
// ECHO THE PAGENATION
echo paginate_links( $args );
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2840 次 |
| 最近记录: |