Customizing comments pagination for bootstrap

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"/ispan class="screen-reader-text"' . __( 'Previous', 'twentyseventeen' ) . '/span',
    'next_text' = 'span class="screen-reader-text"' . __( 'Next', 'twentyseventeen' ) . '/spani class="fa fa-arrow-left" aria-hidden="true"/i',
) );

Topic comments-template twitter-bootstrap paginate-comments-links paginate-links comments Wordpress

Category Web


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.