Pagination bug, renders only two pages and doesn't show the rest of articles in other pages

I’m trying to build my own blog and i’ve found myself lost with this issue.

I have 30 articles, and pagination is set to show only 8 articles per page.

First page shows my latest 8 articles without a problem, second page shows only 1 article.
Doesn’t matter how plenty articles I add, pagination generates only two pages, and the rest of articles are ‘lost’. Any ideea? here’s also my code, maybe i done something wrong thanks :D.

<ul>
  <?php foreach ($list = $page->children()->paginate(8) as $item): ?>
  <li><!-- item html --></li>
  <?php endforeach ?>
</ul>

<?php $pagination = $list->pagination() ?>
<nav class="navpag">
  <ul>

    <?php if ($pagination->hasPrevPage()): ?>
    <li>
      <a href="<?= $pagination->prevPageURL() ?>">‹</a>
    </li>
    <?php else: ?>
    <li>
      <span>‹</span>
    </li>
    <?php endif ?>

    <?php foreach ($pagination->range(10) as $r): ?>
    <li>
      <a<?= $pagination->page() === $r ? ' aria-current="page"' : '' ?> href="<?= $pagination->pageURL($r) ?>">
        <?= $r ?>
      </a>
    </li>
    <?php endforeach ?>

    <?php if ($pagination->hasNextPage()): ?>
    <li>
      <a href="<?= $pagination->nextPageURL() ?>">›</a>
    </li>
    <?php else: ?>
    <li>
      <span>›</span>
    </li>
    <?php endif ?>

  </ul>
</nav>

<main class="articolele" role="main">


<?php foreach($articles = $page->children()->listed()->flip()->paginate(8) as $article): ?>

  <article class="card hvr-float">
    <?php if($image = $article->image()): ?>
    <img class="imaginecard" src="<?= $image->url() ?>" alt="" loading="lazy">
    <?php endif ?>
    <h2 class="titlucard"><a class="titlucarda" href="<?= $article->url() ?>"><?= $article->title()->html() ?></a></h2>
    <div class="continutcardcontainer">
    <p class="continutcard"><?= $article->text()->excerpt(150) ?></p>
    </div>
    <?= $article->intro()->kirbytext() ?>
    <div class="vezireteta">
    <a href="<?= $article->url() ?>">Vezi Rețeta</a>
    <p class="dataarticol"><svg class="svgtime" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="https://retete.pe-zona.ro">
    <path d="M9 7H11V12H16V14H9V7Z" fill="currentColor" />
    <path
    fill-rule="evenodd"
    clip-rule="evenodd"
    d="M22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12ZM20 12C20 16.4183 16.4183 20 12 20C7.58172 20 4 16.4183 4 12C4 7.58172 7.58172 4 12 4C16.4183 4 20 7.58172 20 12Z"
    fill="currentColor"/></svg><?= $article->Published()->html() ?></p>
    </div>
  </article>

  <?php endforeach ?>
</main>

How are these two snippets related?

1 Like

Both are in default.php

navpag snippet contains the first code block from my main post, pagination code
body snippet contains the second code block from my main post, article content cards

<?php snippet('headerhome') ?>
<?php snippet('breadcrumb') ?>
<?php snippet('body') ?>
<?php snippet('navpag') ?>
<?php snippet('footer') ?>
<?php snippet('sidebar') ?>

If you use two pagination objects in the same page, you need to give them different parameters

$articles = $page->children()->listed()->flip()->paginate(8, ['variable' => 'articlepage']);
foreach ( $articles as $article) { 
//...
}
1 Like

Just one pagination is present on my page. Body snippet with navpag snippet are connected.
I just followed documentation. Also if i add your code i get an error like unexpected paramenter “;”.

Body:
<?php foreach($articles = $page->children()->listed()->flip()->paginate(8) as $article): ?>

Navpag:

<ul>
  <?php foreach ($list = $page->children()->paginate(8) as $item): ?>
  <li><!-- item html --></li>
  <?php endforeach ?>
</ul>

<?php $pagination = $list->pagination() ?>
<nav class="navpag">
  <ul>

<?php if ($pagination->hasPrevPage()): ?>
<li>
  <a href="<?= $pagination->prevPageURL() ?>">‹</a>
</li>
<?php else: ?>
<li>
  <span>‹</span>
</li>
<?php endif ?>

<?php foreach ($pagination->range(10) as $r): ?>
<li>
  <a<?= $pagination->page() === $r ? ' aria-current="page"' : '' ?> href="<?= $pagination->pageURL($r) ?>">
    <?= $r ?>
  </a>
</li>
<?php endforeach ?>

<?php if ($pagination->hasNextPage()): ?>
<li>
  <a href="<?= $pagination->nextPageURL() ?>">›</a>
</li>
<?php else: ?>
<li>
  <span>›</span>
</li>
<?php endif ?>

  </ul>
</nav>

Maybe this error is caused by divs from my body, pretty nooob with php

It’s nevertheless a bit confusing because you paginate both collections, $articles and $list, but it seems there is only one pagination object, the one for $list. Whats the purpose of paginatiing $articles`, then?

1 Like