I'm interested in how to make the pagination working. I tried everything, but it didn't work.
I tried after while echo paginate_links() and still nothing... I don't understand
This is navigation to filter ALU, PVC or ALL doors
<article id="post-<?php the_ID(); ?>" <?php post_class('container-fluid py-5'); ?>>
<div class="container py-5">
<div class="section-title position-relative text-center">
<h6 class="text-uppercase text-primary mb-3" style="letter-spacing: 3px;">Was wir haben</h6>
<h1 class="font-secondary display-4">Katalog</h1>
</div>
<!-- FILTERS -->
<div class="filters" id="productsDoorsSelect">
<p>Kategorien</p>
<span class="filter btn btn-primary text-uppercase" data-filter="all">ALL</span>
<span class="filter btn btn-primary text-uppercase" data-filter="alu">alu</span>
<span class="filter btn btn-primary text-uppercase" data-filter="pvc">pvc</span>
</div>
<!-- FILTERS -->
</div>
This is query for custom post type
<!-- PRODUCTS DOORS -->
<div class="container py-5 projects">
<div class="row-products" id="doorsProducts" >
<?php
$productsQuery = new WP_Query (array(
'post_type' => 'products_catalog'
));
if($productsQuery->have_posts()):
while($productsQuery->have_posts()):
$productsQuery->the_post();
?>
<div class="col-lg-4-products mb-3 project" data-filter="<?php the_field('doors_category_field') ?>">
<div class="product-item mb-2">
<div class="product-img">
<img class="img-fluid" src="<?php the_post_thumbnail_url() ?>" alt="">
<a type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalLong<?php the_title()?>">
<i class="fa fa-2x fa-plus text-white"></i>
</a>
</div>
<div class="bg-secondary text-center p-4">
<h3 class="m-0"><?php the_title() ?></h3>
</div>
</div>
</div>
<?php endwhile; endif; ?>
</div>
</div>
<!-- PRODUCTS DOORS -->
This is modals (after click on element modal with details)
<!-- Modal -->
<?php
$productsQuery = new WP_Query (array('post_type' => 'products_catalog'));
if($productsQuery->have_posts()):
while($productsQuery->have_posts()):
$productsQuery->the_post();
?>
<div class="modal fade" id="exampleModalLong<?php the_title() ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle"
aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle"><?php the_title() ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?php the_post_thumbnail('post-thumbnail', ['class' => 'img-fluid mb-4']); ?>
<?php the_content();?>
</div>
</div>
</div>
</div>
<?php endwhile; endif; ?>
<!-- Modal -->
My Answer:
To get pagination working on your page using PHP and WordPress, you can follow these steps:
1. Make sure you have a loop in your template file that displays the posts you want to paginate. This loop should be inside a query that retrieves the posts you want to display.
2. Use the `paginate_links()` function provided by WordPress to generate the pagination links. This function takes an array of arguments that you can use to customize the pagination output.
3. Here is an example of how you can use `paginate_links()` in your template file:
php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
4. Make sure to place this code where you want the pagination links to appear on your page.
5. If you are filtering posts by ALU, PVC, or ALL doors, you can modify the query arguments to include the filter criteria. You can use `pre_get_posts` hook to modify the main query before it is executed.
6. If you are still having trouble getting pagination to work, make sure that your query is correctly set up and that the number of posts per page is set to a value greater than 0.
By following these steps and customizing the pagination function to fit your specific needs, you should be able to get pagination working on your page using PHP and WordPress.
Rate this post
3 of 5 based on 8380 votesComments