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?

1 Answer
1

    $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.

Leave a Reply

Your email address will not be published. Required fields are marked *