【问题标题】:How to filter posts by category in Camaleon CMS?如何在 Camaleon CMS 中按类别过滤帖子?
【发布时间】:2017-06-28 13:40:30
【问题描述】:

我正在尝试在我的 Rails 项目中按类别过滤帖子,我正在使用 Camaleon CMS。我的基本要求是只显示特定的帖子。

例如,仅显示属于“水果”类别的帖子?

这是我使用的代码:

  <% current_site.the_posts(current_theme.get_field("recent_post_type")).latest.limit(current_theme.get_field("home_qty")).decorate.each do |post| %>
      <!-- PORTFOLIO ITEM -->
      <div class="col-lg-3 col-md-3 col-sm-6 col-xs-6 text-center discussion-bot-box">
        <h4><%= post.the_title %> <span>(299)</span></h4>
        <p><%= post.the_content.html_safe %></p>
      </div> <!-- /col -->
  <% end %>

【问题讨论】:

  • 你可以使用current_theme.the_posts.where(category: 'fruits')

标签: ruby-on-rails ruby ruby-on-rails-4 camaleon


【解决方案1】:

先尝试查找类别:

category = current_site.the_full_categories.find_by(name: 'Fruits')

然后装饰并获取相关帖子:

category.decorate.the_posts

【讨论】:

  • 这太棒了,我无法表达我有多高兴,非常感谢你,你能告诉我你从哪里得到的吗?我的意思是你有任何链接可以提供这些信息。
  • Camaleon CMS 文档不是最好的,大部分的东西我只是去看看源代码。
猜你喜欢
  • 2021-10-26
  • 1970-01-01
  • 2022-01-18
  • 1970-01-01
  • 2017-06-12
  • 2021-06-23
  • 1970-01-01
  • 1970-01-01
  • 2020-11-10
相关资源
最近更新 更多