php – adding pagination to a foreach loop in wordpress


Am looking for a way to implement pagination on my categories i tried to use paginated_links(); functions but it works only for posts, and not the actual categories. I have looked around and it seems this is a little trickier than I was expecting…

        array('parent' => $cat->cat_ID)
                // loop through the categries
                foreach ($cats as $cat) {
          echo '<div class="card">';
                    // setup the cateogory ID
                    $cat_id= $cat->term_id;
          echo '<div class="card-body">';
          // make images for the category
          echo '<div class="card-title"><a href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a> <i class="fas fa-arrow-right"></i></div>';
          echo '</div>';
                    // create a custom wordpress query

                    if (have_posts()) : while (have_posts()) : the_post(); ?>
          <?php echo '<div class="blog-list-points">' ?>
                        <?php // create our link now that the post is setup ?>
            <a href="<?php the_title();?>">
            <?php the_excerpt(); ?>
          <?php echo '</div>'?>
                    <?php endwhile; endif; echo ' </div> '// done our wordpress loop. Will start again for each category ?>
                <?php } 
        // done the foreach statement ?>

adrien duval 1 year 2022-02-06T08:35:01-05:00 0 Answers 0 views 0

Leave an answer