0

I wrote this code:

<div class="col-12">
                                        <div class="pagination d-flex justify-content-center mt-5">
                                            <!-- <a href="#" class="rounded">&laquo;</a>
                                            <a href="#" class="active rounded">1</a>
                                            <a href="#" class="rounded">2</a>
                                            <a href="#" class="rounded">3</a>
                                            <a href="#" class="rounded">4</a>
                                            <a href="#" class="rounded">5</a>
                                            <a href="#" class="rounded">6</a>
                                            <a href="#" class="rounded">&raquo;</a> -->
                                            <?php
                                            $total_pages = $loop->max_num_pages;
                                            if ($total_pages > 1){
                                        
                                                $current_page = max(1, get_query_var('paged'));
                                        
                                                $base_url = get_pagenum_link(1);
                                                $paged_url = add_query_arg('paged', '%#%', $base_url); // Replace %%% with actual page number

                                                echo paginate_links(array(
                                                    'base' => $paged_url,
                                                    'format' => '%#%',
                                                    'current' => $current_page,
                                                    'total' => $total_pages,
                                                    'prev_text'    => __('« prev'),
                                                    'next_text'    => __('next »'),
                                                ));
                                            }
                                            wp_reset_postdata();
                                            ?>
                                        </div>
                                    </div>

In this code, the commented out part is actually how the active page number inside pagination should look like, but I am having no ideas on how I can manage this issue.

1 Answer 1

1

By default paginate_links() gives you several ways to target the current page:

  1. It will replace the a element with a span element, because there's no point in a page linking to itself
  2. It adds the class current to the span
  3. It adds the aria-current attribute to the span

Any one of these can be used to apply whatever styling you want

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.