php – How do I get pagination for get_posts() in WordPress or do I have to rewrite the whole code?

Question

I inhertited a WordPress page with a long post list. I need it to have pagination to not load 500 pictures at once. Would I have to rewrite everything with WP_Query() or is there an easier way?

<?php
$args = array(
    "posts_per_page"   => 5,
    "paged"            => 1,
    'category_name'    => 'Publishing',
    "orderby"          => "post_date",
    "order"            => "DESC",
    "post_type"        => "post",
    "post_status"      => "publish"
);

$posts_array = get_posts($args); 




 foreach($posts_array as $post)
 {  $id=$post->ID; $image=get_the_post_thumbnail($id, 'full'); 
    if( class_exists('Dynamic_Featured_Image') ) {
        global $dynamic_featured_image;
    
        $featured_images = $dynamic_featured_image->get_featured_images($id );
        
     }

     echo "<div class="direkt">".get_the_date( 'd F Y', $post->ID )."<a href=".get_permalink($post->ID)."?kat=publishing> [Direct Link] </a></div>";
    ?>
        <div class="custompost_wrapper">
            <div class="custompost">
                <div class="splide" data-splide="{"lazyLoad": "nearby"}">
                    <div class="splide__track">
                        <ul class="splide__list">
                            <li class="splide__slide">
                                <?php echo $image; ?>
                            </li>
                            <?php foreach($featured_images as $featured_image): ?>
                                <li class="splide__slide">
                                    <img src="<?php echo $featured_image['full']; ?>"
                                    data-splide-lazy="<?php echo $featured_image['full']; ?>"
                                    loading="lazy">
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

<?php

   echo "<div class="custompost_contentwrapper">
        <strong>". $post->post_title . "</strong><br>";
   echo "<div class="thecontent">" . $post->post_content . "</div>";
   echo "<div class="spacer"></div></div>";
 } 


?>

0
Tom 8 months 2021-12-02T10:41:30-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse