I'm developing a site using Understrap's starter theme. I wanted to use a split design on home.php where the latest post is displayed on top of the others "full width" while the rest are positioned below within a three column layout.
Thanks to this very helpful post it works flawlessly.
However, now I'm having a hard time getting the pagination to work in conjunction to the altered loop. Without doing anything, the pagination shows up at the bottom of the page but when I press the link, same page is coming up.
This is my code:
<?php
$args = [
'posts_per_page' => 10
];
$q = new WP_Query($args);
if ($q->have_posts()) {
while ($q->have_posts()) {
$q->the_post();
if ($q->current_post < 1) { ?>
<!-- start .banner -->
<section id="banner" class="ts-75 bs-100">
<div class="content">
<h1 class="banner-blog-title">
<a class="post-link" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h1>
<p class="lead"><?php echo wp_trim_words(get_the_excerpt(), 40); ?></p>
<a href="<?php the_permalink(); ?>" class="btn btn-outline-secondary">Läs hela texten</a>
</div>
<a class="img-link half-w-lg" href="<?php the_permalink(); ?>">
<?php if (has_post_thumbnail()) : ?>
<img src="<?php the_post_thumbnail_url('blog_image'); ?>" class="img-fluid fit-cover" alt="<?php echo $image_alt; ?>">
<?php endif; ?>
</a>
</section><!-- / .banner -->
<?php
}
} ?>
<hr class="hr-royal hr-royal-thick bs-100">
<div class="card-section">
<div class="row mx-lg-n5">
<?php
$q->rewind_posts();
while ($q->have_posts()) {
$q->the_post();
if ($q->current_post >= 1 && $q->current_post <= 10) { ?>
<div class="col-md-6 col-xl-4 mb-5 px-lg-5">
<div class="card">
<div class="card-image-wrapper">
<a href="<?php the_permalink(); ?>">
<?php if (has_post_thumbnail()) : ?>
<img src="<?php the_post_thumbnail_url('blog_image'); ?>" class="card-img-top fit-cover" alt="<?php echo $image_alt; ?>">
<?php endif; ?>
</a>
</div>
<div class="card-body">
<a href="#" class="card-post-date-link">
<div class="card-post-date">
<p class="card-post-date-text--lg"><?php the_time('d'); ?></p>
<p class="card-post-date-text--sm"><?php the_time('M'); ?></p>
</div>
</a>
<h4 class="card-title">
<a class="card-post-link" href="#"><?php the_title(); ?></a>
</h4>
<?php if (get_field('ingress')) : ?>
<div class="lead-wrapper">
<p class="lead"><?php echo wp_trim_words(get_field('ingress'), 32); ?></p>
</div>
<?php else : ?>
<p class="lead"><?php echo wp_trim_words(get_the_excerpt(), 24); ?></p>
<?php endif; ?>
</div>
</div>
</div>
<?php
}
}
// wp_reset_postdata(); // Initial reset
} ?>
</div>
</div>
<!-- This is where I try to continue the loop and retrieve the correct post data for pagination -->
<?php
$q->rewind_posts();
while ($q->have_posts()) {
$q->the_post();
if ($q->current_post > 10) { ?>
<?php understrap_pagination();
}
wp_reset_postdata();
} ?>
Any help appreciated! Thank you.