Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a custom comments page with pagination.

I have non-hierarchical custom type "apartments".

It makes urls like:

/apartments/ - for acrhive
/apartments/%id%/ - for post page
/apartments/%id%/comments-page-X/ - for comments (X is some number)

How do I create page /apartments/%id%/questions/ for comments? And remove /apartments/%id%/comments-page-X/ if possible.

I would like to make this url structure for comments:

/apartments/%id%/questions/ - first page of the comments
/apartments/%id%/questions/page/X/ - pagination for comments (X is some number)

What is the solution?

share|improve this question
    
you can do that with paginate_comments_links() and setting your base to questions, codex.wordpress.org/Function_Reference/paginate_comments_links and then add your rewrite rule. –  Bainternet Apr 18 '11 at 3:13
1  
can you give a coded example? I will accept your answer if it works. –  ilovewordpress Apr 18 '11 at 11:13

1 Answer 1

up vote 1 down vote accepted
    $args = array('post_id'=>get_the_ID(), 'status'=> 'approve');
    $all_comm = get_comments($args);
    $per_page = get_option("comments_per_page");
    if(!$per_page)
    $per_page = 4;
    $cpage = get_query_var("cpage");
    if(!$cpage)
    $cpage = 1;
    if(round(count($all_comm)/$per_page) == 0)
    $total = 1;
    else
    $total = round(count($all_comm)/$per_page);
    $args_comments = array(
        'base' => add_query_arg( 'cpage', '%#%' ),
        'format' => "",
        'total' => $total,
        'current' => $cpage,
        'echo' => false,
        'add_fragment' => '#reviews'
    );
    $pagi_comments = paginate_comments_links($args_comments);
    $args = array('post_id'=>get_the_ID(), 'status'=> 'approve', 'number' => $per_page, 'offset' => $per_page*($cpage-1));
    $all_comm = get_comments($args);
    if($all_comm)
    foreach($all_comm as $as){ print_r($as); }
    echo $pagi_comments;

I hope it helps lot to you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.