【问题标题】:OctoberCMS Blog plugin with Recent postOctoberCMS 博客插件与最近的帖子
【发布时间】:2021-05-24 14:57:00
【问题描述】:

我有一个来自客户的奇怪要求。我正在使用 OctoberCMS 博客插件 https://octobercms.com/plugin/rainlab-blog,它的工作方式符合我的预期。

但是,我有一个名为 Recent Post 的部分,其中我在同一页面中显示了 1 个最新的最近帖子和一个博客列表,其中最新的博客列表作为第一个博客。

现在我的客户说,Recent Post中的博客和第一个博客一样,是最新的博客,显然是一样的。

因此,我使用 Twig 的切片函数 https://twig.symfony.com/doc/3.x/filters/slice.html 从列表中隐藏/删除第一个博客。这是我的做法。

 {% if this.page.id == 'blog' %}
    {% if posts.currentPage == 1 %}
      {% set sliceBlogs = 1 %}
    {% else  %}
      {% set sliceBlogs = 0 %}
    {% endif %}
  {% else %}
    {% set sliceBlogs = 0 %}
  {% endif %}

{% for post in posts | slice(sliceBlogs) %}

这里如你所见,我已经做了一个条件,如果只找到博客列表页面并且找到第一页,那么只有它会隐藏/删除博客列表中的第一个博客。

但是在这里我遇到了Post per page 的问题。目前我已经设置为11,但是当它在博客列表的第一页上时,因为我已经切片/跳过了第一个博客,它显示的少了一个,这是不正确的..

所以我的问题是,我怎样才能使这部分正确并确保它在每个页面上显示相同数量的最大博客数?

谢谢

【问题讨论】:

    标签: octobercms octobercms-plugins


    【解决方案1】:

    好的,伙计们,最终我以这种方式解决了..

    我在我的博客 CMS 页面中添加了以下代码..

    function onStart()
    {       
        
        $latestPost = RainLab\Blog\Models\Post::isPublished()->orderBy('published_at', 'desc')->first();
        $this->blogPosts->setProperty('exceptPost', $latestPost->id);
    }
    

    它将从博客列表中删除第一个最新帖子。

    谢谢

    【讨论】:

      猜你喜欢
      • 2019-07-25
      • 2019-08-24
      • 2016-03-25
      • 2018-06-17
      • 2011-07-27
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多