分页是“有效的”,但是没有显示用于导航分页的链接

我可以访问.../page/1.../page/2etc ...,并且它显示帖子,因此我知道分页在技术上是可行的,但是分页链接未显示。

木材

use const Flynt\Archives\POST_TYPES;

global $paged;

if (!isset($paged) || !$paged){
  $paged = 1;
}

$context = Timber::get_context();

$args = array(
  'numberposts' => -1,'post_type' => 'event','meta_key' => 'start_date','orderby' => 'meta_value','order' => 'ASC','posts_per_page' => 6,'paged' => $paged
);

$context['events'] = new Timber\PostQuery($args);
$context['options'] = get_fields('options');

Timber::render('templates/classes-and-registration.twig',$context);

树枝

<ul class="pagination">
          {% if posts.pagination.prev %}
            <li class="page-item">
              <a class="page-link" href="{{ posts.pagination.prev.link }}" aria-label="Previous">
                <span aria-hidden="true">&laquo;</span>
                <span class="sr-only">Previous</span>
              </a>
            </li>
          {% endif %}
          {% for page in posts.pagination.pages %}
            <li class="page-item">
              {% if page.link %}
                <a class="page-link" href="{{ page.link }}">{{ page.title }}</a>
              {% else %}
                <span class="{{page.class}}">{{page.title}}</span>
              {% endif %}
            </li>
          {% endfor %}
          {% if posts.pagination.next %}
            <li class="page-item">
              <a class="page-link" href="{{ posts.pagination.next.link }}" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
                <span class="sr-only">Next</span>
              </a>
            </li>
          {% endif %}
        </ul>
jialinjl 回答:分页是“有效的”,但是没有显示用于导航分页的链接

我看到您使用以下代码在PHP中准备帖子:

$context['events'] = new Timber\PostQuery($args);

但是,在分页中,您可以访问posts上的分页,该分页可能还不存在。您将不得不将events重命名为posts,或者从events而不是posts访问分页。

{# … #}


{% for page in events.pagination.pages %}
<li class="page-item">
    {% if page.link %}
    <a class="page-link" href="{{ page.link }}">{{ page.title }}</a>
    {% else %}
    <span class="{{page.class}}">{{ page.title }}</span>
    {% endif %}
</li>
{% endfor %}


{# … #}

此外,我看到在您的$args数组中,您同时定义了posts_per_pagenumberpostsnumberposts arg实际上是posts_per_page的别名。您可能应该只定义posts_per_page

本文链接:https://www.f2er.com/2657440.html

大家都在问