-1

我正在尝试在我的 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 %>
4

1 回答 1

1

尝试先找到类别:

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

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

category.decorate.the_posts
于 2017-07-04T09:55:13.430 回答