yii 下一篇文章部分没有在craftcms工作有人知道这里出了什么问题吗?

bvn4nwqk  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(121)

我一个手工cms项目,我有文章,一旦点击文章,我就可以阅读这些文章,在右侧内容中,我有一个名为Next Article的选项卡,但当点击时,这里没有任何响应,即Live Site -http://ambitmagazine.co.uk/poems/ambit-poetry-competition-2018
屏幕截图-https://prntscr.com/o9gkph
_entry.html

{% extends "_layout" %}

{% block content %}

{% set issue = entry.issue.first() %}
{% set nextArticle = craft.entries.section('articles').after(entry.postDate).order('postDate asc').limit(1).find() %}

<div class="article section{% if entry.largeText %} article--larger-text{% endif %}">
    <div class="article__inner section__inner">

        {% include 'articles/_partials/article-header' with { article: entry, issue: issue } only %}
        {% include "articles/_types/" ~ entry.type %}
        {% if entry.relatedAuthor|length > 0 %}
            {% include 'articles/_partials/article-footer' with { article: entry } only %}
        {% endif %}

        {% if nextArticle|length > 0 %}
            <div class="next-item">
                <a href="{{nextArticle[0].url}}" class="next-item__inner">
                    <span><strong>Next Artcile</strong></span>
                    <span>\</span>
                    <span>{{nextArticle[0].title}}</span>
                </a>
            </div>
        {% endif %}
        <div class="article__sidebar-inner"></div>
    </div>

    <div class="article__sidebar-outer"></div>
</div>
ep6jt1vc

ep6jt1vc1#

.after正在执行〉=操作,因此当前文章将包含在结果中,并且几乎可以肯定将是第一个选项。
执行类似于.after(entry.postDate|date_modify('+1 second'))的操作将排除当前文章,并应给予您正在查找的内容。
对于您的查询来说,保持时间不变可能更清楚,但按id显式排除当前条目:

{% set nextArticle = craft.entries()
        .section('articles')
        .after(entry.postDate)
        .id(['not', entry.id])
        .order('postDate asc')
        .one() %}

相关问题