0

ページネーションがうまく機能していません。イベントは 4 つだけで、ページネーションは 1 ページあたり 3 つに設定されています。2 番目のページを読み込むと、最後の投稿ではなく、最初のイベントが自動的に読み込まれます。

私のコードは以下です。私はカービー コンテンツ マネージャーを使用していますが、これは Web サイト全体でかなり均一であると思います。イベントループ内のループが原因で機能していないと確信していますが、それを修正する方法がわかりません。

<div id="main-container">
  <div class="content">
    <div class="container">
      <div class="row">
        <div class="col-md-12 content-block">
          <ul class="events-list">
          <?php $events = $page->children()->paginate(3);
            $i = -1;
            foreach($events as $event) {
              $i++; ?>
              <li class="event-list-item">
                <?php $calendar = page('events')->children()->nth($i)->calendar()->yaml();
                  foreach($calendar as $calendarEntry) { ?>
                      <span class="event-date">
                        <span class="date">
                          <?php 
                            $eventday=strtotime($calendarEntry['_begin_date']);
                            echo date('j',$eventday);  
                          ?>
                        </span>
                        <span class="month">
                          <?php 
                            $eventmonth=strtotime($calendarEntry['_begin_date']);
                            echo date('M',$eventmonth);  
                          ?>
                        </span>
                        <span class="year">
                          <?php 
                            $eventmonth=strtotime($calendarEntry['_begin_date']);
                            echo date('Y',$eventmonth);  
                          ?>
                        </span>
                      </span>
                      <div class="event-list-cont">
                        <span class="meta-data">Starts:
                          <?php $eventday=strtotime($calendarEntry['_begin_date']);
                          echo date('l',$eventday);  ?>, 
                          <?php $eventstarttime=strtotime($calendarEntry['_begin_time']);
                          echo date('g:i A',$eventstarttime); $eventday=strtotime($calendarEntry['_end_date']);
                          if ($eventday){ ?>
                            | Finishes: <?php echo date('l',$eventday); ?>,
                            <?php }  ?>
                          <?php $eventendtime=strtotime($calendarEntry['_end_time']);
                          if($eventendtime) {
                            echo date('g:i A',$eventendtime);
                            }  ?></span>
                        <h4 class="post-title"><a href="<?php echo page('events')->children()->nth($i)->url(); ?>"><?php echo $calendarEntry['eventname'] ?></a></h4>
                        <p>
                          <?php echo page('events')->children()->nth($i)->eventwriteup()->excerpt(250); ?> <a href="<?php echo page('events')->children()->nth($i)->url(); ?>">read&nbsp;more&nbsp;→&lt;/a>
                        </p>
                      </div>
                <?php } ?>
              </li>
            <?php } ?>
          </ul>
          <!-- Page Pagination -->
          <?php
          $list = $page->children()->paginate(3);
          $pagination = $list->pagination();
          ?>
          <nav>
            <ul class="pagination pagination-lg">
              <?php if($pagination->hasPrevPage()): ?>
              <li>
                <a href="<?php echo $pagination->prevPageURL() ?>">&larr;</a></li>
                <?php else: ?>
                <li><span>&larr;</span></li>
                <?php endif ?>
              <?php foreach($pagination->range(10) as $r): ?>
                <li><a<?php if($pagination->page() == $r) echo ' class="active"' ?> href="<?php echo $pagination->pageURL($r) ?>"><?php echo $r ?></a></li>
              <?php endforeach ?>
              <?php if($pagination->hasNextPage()): ?>
              <li class="last"><a href="<?php echo $pagination->nextPageURL() ?>">&rarr;</a></li>
              <?php else: ?>
              <li class="last"><span>&rarr;</span></li>
              <?php endif ?>
            </ul>
          </nav> ....
4

1 に答える 1

0

ウォール、ここでお手伝いしたいのですが、コードにもっとコンテキストが必要です. あなたのループにはいくつかの繰り返しがあるようです。ループ内でも $i 変数を使用している理由はわかりません。それを見ると、もっと単純なものでうまくいく可能性があります。

<div id="main-container">
<div class="content">
    <div class="container">
      <div class="row">
        <div class="col-md-12 content-block">
          <ul class="events-list">
          <?php $events = $page->children()->paginate(3);
            foreach($events as $event): ?>
              <li class="event-list-item">
                <?php $calendar = $event->calendar()->yaml();
                  foreach($calendar as $calendarEntry) { ?>
                      <span class="event-date">
                        <span class="date">
                          <?php 
                            $eventday=strtotime($calendarEntry['_begin_date']);
                            echo date('j',$eventday);  
                          ?>
                        </span>
                        <span class="month">
                          <?php 
                            $eventmonth=strtotime($calendarEntry['_begin_date']);
                            echo date('M',$eventmonth);  
                          ?>
                        </span>
                        <span class="year">
                          <?php 
                            $eventmonth=strtotime($calendarEntry['_begin_date']);
                            echo date('Y',$eventmonth);  
                          ?>
                        </span>
                      </span>
                      <div class="event-list-cont">
                        <span class="meta-data">Starts:
                          <?php $eventday=strtotime($calendarEntry['_begin_date']);
                          echo date('l',$eventday);  ?>, 
                          <?php $eventstarttime=strtotime($calendarEntry['_begin_time']);
                          echo date('g:i A',$eventstarttime); $eventday=strtotime($calendarEntry['_end_date']);
                          if ($eventday){ ?>
                            | Finishes: <?php echo date('l',$eventday); ?>,
                            <?php }  ?>
                          <?php $eventendtime=strtotime($calendarEntry['_end_time']);
                          if($eventendtime) {
                            echo date('g:i A',$eventendtime);
                            }  ?></span>
                        <h4 class="post-title"><a href="<?php echo $event->url(); ?>"><?php echo $calendarEntry['eventname'] ?></a></h4>
                        <p>
                          <?php echo $event->eventwriteup()->excerpt(250); ?> <a href="<?php echo $event->url(); ?>">read&nbsp;more&nbsp;→&lt;/a>
                        </p>
                      </div>
                <?php } ?>
              </li>
            <?php } ?>
          </ul>
          <!-- Page Pagination -->
          <?php
          $list = $page->children()->paginate(3);
          $pagination = $list->pagination();
          ?>
          <nav>
            <ul class="pagination pagination-lg">
              <?php if($pagination->hasPrevPage()): ?>
              <li>
                <a href="<?php echo $pagination->prevPageURL() ?>">&larr;</a></li>
                <?php else: ?>
                <li><span>&larr;</span></li>
                <?php endif ?>
              <?php foreach($pagination->range(10) as $r): ?>
                <li><a<?php if($pagination->page() == $r) echo ' class="active"' ?> href="<?php echo $pagination->pageURL($r) ?>"><?php echo $r ?></a></li>
              <?php endforeach ?>
              <?php if($pagination->hasNextPage()): ?>
              <li class="last"><a href="<?php echo $pagination->nextPageURL() ?>">&rarr;</a></li>
              <?php else: ?>
              <li class="last"><span>&rarr;</span></li>
              <?php endif ?>
            </ul>
          </nav> ....

ページネーションの詳細については、この投稿を確認してください:ページネーション

于 2016-05-28T07:47:22.940 に答える