0

我的一个工艺 cms 项目,我有文章,一旦点击文章,我可以阅读这些文章,在右侧的内容中,我有一个选项卡调用 Next article,但是当点击这里没有任何响应时,现场网站 - 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>
4

1 回答 1

0

.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() %}
于 2019-07-23T17:13:28.790 回答