【发布时间】:2018-10-27 06:08:33
【问题描述】:
我正在尝试在我制作的自定义页面模板上进行分页,该模板旨在显示所有帖子(完成后它将成为存档登录页面)。
我设置了使用 `wp_query.显示正确数量的帖子,它们的链接有效,但我无法成功进行分页。
如果我使用下面的设置,我会收到错误:Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: syntax error, unexpected end of file in web/app/uploads/cache/0cefb280e2bc87c5c0311d7606b77c153f8da2b0.php on line 531
我试过了:
- 在
wp-config文件中将 WP_CACHE 设置为 false - 尝试将
prev_text和next_text设置为true - 不包括
$paginate_linkssection - 删除有问题的
cache文件夹(它只是重新创建) - 在关闭
@endwhile之前添加@php wp_reset_postdata() @endphp但这会给我一个意外的 if 错误结束 - 使用
{!! get_the_posts_navigation() !!}只是为了看看会发生什么
我完全被卡住了——我以前在使用 WP 时从未遇到过这样的事情(尽管我是 Blade 模板的新手)。我可以在此自定义页面模板上显示帖子,但无法设置分页 - 到目前为止,它让我一整天都卡住了。
@extends('layouts.app')
@section('content')
@php
global $post;
$args = array(
'prev_text' => false,
'next_text' => false,
'format' => 'page/%#%#posts'
);
@endphp
<div class="news-page-content">
<div class="max-wrap">
<div id="article-list" class="article-list-container">
<div class="article-list">
@php
global $wp_query;
$wp_query = new WP_Query ( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 4,
'orderby' => 'DESC',
'ignore_sticky_posts'=> true,
'nopaging' => false,
'paged' => true
));
@endphp
@if( $wp_query->have_posts() )
@while( $wp_query->have_posts() ) @php $wp_query->the_post() @endphp
<div>
<a href="{{ get_the_permalink() }}">
<h3>{{ the_title() }}</h3>
<h4>{{ get_the_date( 'm/d/Y' ) }}</h4></a>
</div>
@endwhile
@php wp_reset_query() @endphp
@endif
<div class="bottom-pager">
<div class="prev-next">@php posts_nav_link(' ','PREV PAGE','NEXT PAGE') @endphp</div>
<div class="pager">
{!! paginate_links($args) !!}
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
【问题讨论】:
标签: wordpress pagination laravel-blade