列出相关类别页面中的非帖子页面

时间:2015-08-10 10:55:43

标签: jekyll liquid

我有一个Jekyll博客正在运行,但我想做一些看似有点不正统的事情。 基本上,我在func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { var dealer : DealerList var alldealer : TotalDealerList var id : String if scAll.selectedSegmentIndex == 0 { if scMatur.selectedSegmentIndex == 0 { if (self.resultSearchController.active) { dealer = filtereddealers[indexPath.row] } else { dealer = dealers[indexPath.row] } } else { if (self.resultSearchController.active) { dealer = filtereddealers[indexPath.row] } else { dealer = sorteddealers[indexPath.row] } } //Create a message box with actions for the user. let actionSheetController: UIAlertController = UIAlertController(title: "What to do with:", message: "'\(dealer.dlName)'?", preferredStyle: .ActionSheet) let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in //Just dismiss the action sheet } //starts a phonecall to the selected dealer let callAction: UIAlertAction = UIAlertAction(title: "Call", style: .Default) { action -> Void in var phonenr = "0634563859" let alert2 = UIAlertController(title: "Please confirm", message: "Call '\(dealer.dlName)' at \(phonenr)?", preferredStyle: UIAlertControllerStyle.Alert) alert2.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.Default, handler: nil)) alert2.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default) { UIAlertAction in self.callNumber(phonenr) }) self.presentViewController(alert2, animated: true, completion: nil) } //action that opens the DealCustView. Pass data from this view to the next. ID is used in the next view. let showcustomersAction: UIAlertAction = UIAlertAction(title: "Customers", style: .Default) { action -> Void in let reportview = self.storyboard?.instantiateViewControllerWithIdentifier("dealcustList") as! DealCustView reportview.id2 = dealer.dlSCode reportview.sourceid = self.id self.navigationController?.pushViewController(reportview, animated: true) } //add the actions to the messagebox actionSheetController.addAction(cancelAction) actionSheetController.addAction(showcustomersAction) actionSheetController.addAction(callAction) //present the messagebox dispatch_async(dispatch_get_main_queue(), { self.presentViewController(actionSheetController, animated: true, completion: nil) }) } else { if scMatur.selectedSegmentIndex == 0 { if (self.resultSearchController.active) { alldealer = filteredalldealers[indexPath.row] } else { alldealer = alldealers[indexPath.row] } } else { if (self.resultSearchController.active) { alldealer = filteredalldealers[indexPath.row] } else { alldealer = sortedalldealers[indexPath.row] } } /// //Create a message box with actions for the user. let actionSheetController: UIAlertController = UIAlertController(title: "What to do with:", message: "'\(alldealer.tdlName)'?", preferredStyle: .ActionSheet) let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in //Just dismiss the action sheet } //starts a phonecall to the selected dealer let callAction: UIAlertAction = UIAlertAction(title: "Call", style: .Default) { action -> Void in var phonenr = "0634563859" let alert2 = UIAlertController(title: "Please confirm", message: "Call '\(alldealer.tdlName)' at \(phonenr)?", preferredStyle: UIAlertControllerStyle.Alert) alert2.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.Default, handler: nil)) alert2.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default) { UIAlertAction in self.callNumber(phonenr) }) self.presentViewController(alert2, animated: true, completion: nil) } //action that opens the DealCustView. Pass data from this view to the next. ID is used in the next view. let showcustomersAction: UIAlertAction = UIAlertAction(title: "Customers", style: .Default) { action -> Void in let reportview = self.storyboard?.instantiateViewControllerWithIdentifier("dealcustList") as! DealCustView reportview.id2 = alldealer.tdlSCode reportview.sourceid = self.id self.navigationController?.pushViewController(reportview, animated: true) } //add the actions to the messagebox actionSheetController.addAction(cancelAction) actionSheetController.addAction(showcustomersAction) actionSheetController.addAction(callAction) //present the messagebox dispatch_async(dispatch_get_main_queue(), { self.presentViewController(actionSheetController, animated: true, completion: nil) }) } } } 中有博客帖子,在/_posts的另一个文件夹中有一组静态页面。

这些项目页面的顶部如下所示:

/projects

现在,重要人物:每个类别(例如上面示例中的数据新闻)都有一个包含唯一网址的网页,其中汇总了属于此类别的帖子。

我希望属于这些类别的项目聚合在这些相同的页面上,例如数据新闻类别页面将包含项目列表和帖子列表,所有这些都是此类别的一部分。

我设法用

列出每个类别页面上的所有项目
---
layout: project
title: My cool project
categories:
- Data Journalism
status: active
---

<ul class="posts"> {% for page in site.pages %} {% if page.layout == 'project' %} {% if page.status == 'active' %} <h2><a href="{{ page.url }}">{{ page.title }}</a></h2> <div> {{ page.description }}</div> {% endif %} {% endif %} {% endfor %} </ul> 中添加。但是它显示了所有项目,而不仅仅是属于页面类别的项目。在示例中,_layouts/category_index.html应仅列在My cool project类别页面中。

你能帮忙吗?我非常感激!

编辑:感谢Davic Jacquel的解决方案。他的回答如下,标记为已解决,这是我必须做出的调整:

Data Journalism

1 个答案:

答案 0 :(得分:1)

修改:阅读您的插件代码让我意识到您的所有类别页面都有page.category变量。

注意:当前页面的数据存储在page变量中。因此,当您循环时,请不要使用page作为存储变量来避免冲突。

_layouts / category_index.html

---
layout: default
---
<ul class="posts">
  {% for p in site.pages %}
    {% if p.layout == 'project' and p.status == 'active' %}
      {% if p.categories contains page.category %}
        <h2><a href="{{ site.baseurl }}{{ p.url }}">{{ p.title }}</a></h2>
        <div> {{ p.description }}</div>
      {% endif %}
    {% endif %}
  {% endfor %}
</ul>