1

I want to customize the comments pagination to support Bootstrap, I have these lines in my theme file but I need more customization to display Bootstrap pagination style

<?php the_comments_pagination( array(
    'prev_text' => '<i class="fa fa-arrow-right" aria-hidden="true"></i><span class="screen-reader-text">' . __( 'Previous', 'twentyseventeen' ) . '</span>',
    'next_text' => '<span class="screen-reader-text">' . __( 'Next', 'twentyseventeen' ) . '</span><i class="fa fa-arrow-left" aria-hidden="true"></i>',
) );

1 Answer 1

1

Just replace that snippet for this one:

    <?php
      $pages = paginate_comments_links(['echo' => false, 'type' => 'array']);

      if( is_array( $pages ) ) {
        $output = '';
        foreach ($pages as $page) {
          $page = "\n<li>$page</li>\n";
          if (strpos($page, ' current') !== false) 
            $page = str_replace([' current', '<li>'], ['', '<li class="active">'], $page);
          $output .= $page;
        }
        ?>
        <nav aria-label="Comment navigation">
            <ul class="pagination">
                <?=$output?>
            </ul>
        </nav>
    <?php
      }
    ?>

This code retrieves the comments as an array, this allows to customize each one as an unordered list formatted just for Bootstrap.

It also replaces the current WP class for the active that Bootstrap uses to mark the current page.

For this code to work you also need to add the bootstrap.css file in your header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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