Drupal 7:在视图中排序多个内容类型,具有不同的日期字段 [英] Drupal 7: Sorting multiple content types in Views, with different date fields

查看:631
本文介绍了Drupal 7:在视图中排序多个内容类型,具有不同的日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Drupal 7,其中包含Views,Feeds和Views PHP模块(除其他外,我认为这些是唯一相关的)。

I'm using Drupal 7, with the Views, Feeds and Views PHP modules (among others, but I think those are the only relevant ones).

我的目标是一个单一的视图,它结合了(a)通过Feeds模块引入的多个RSS Feed,(b)我自己的两个或三个内容类型,用于在我的网站上手动创建的contant。结果将是一个块和一个页面,其中包含所有我最新的作品,无论它在哪里 - 我自己的网站或另一个网站(当然,只要该其他网站有一个RSS源)。

My goal is a single view that combines (a) multiple RSS feeds brought in through the Feeds module, (b) two or three content types of my own, for contant created manually on my site. The result will be a block and a page that has a stream of all my latest work, wherever it is -- my own site or another site (as long as that other site has an RSS feed, of course).

理想的结果将显示一个单独的列表,按日期排列,混合项目,而不考虑内容类型。

The ideal result would show a single list, sorted by date, mingling the items without regard for content type.

我的问题:Feeds模块和我的自定义内容类型有不同的日期字段。我的内容类型有一个名为原始日期的字段,当我创建内容时,我设置了一个字段(例如,添加一篇我三年前写的文章 - 我显然希望它被发布时排序,而不是当我添加到现场)。但是,每个feed_item都有一个日期字段,发布日期,对应于RSS Feed中的日期,并通过RSS接收与该项目的其余部分。

My problem: The Feeds module and my custom content types have different date fields. My content types have a field called Original Date, which I set when I create content (eg, adding an article I wrote three years ago -- I clearly want it to be sorted by when it was published, not when I added it to the site). However, each feed_item has a date field, Published Date, that corresponds to the date in the RSS feed and is received with the rest of the item by RSS.

我有尝试使用Views PHP功能,以各种方式使用if / then语句。例如,我检查content_type是什么,然后根据内容类型将变量设置为原始日期或发布日期。或者,我测试了原始日期字段是否设置;如果是这样,我返回该字段,否则返回发布日期字段。他们都以各种方式失败。大部分的PHP错误,即使对匿名用户也是可见的(显然是一个问题)。

I have tried to use the Views PHP functionality to use if/then statements, in a variety of ways. For example, I check what the content_type is, and then set a variable to either the Original Date or by the Published Date, depending on the content type. Alternatively, I have tested whether the Original Date field is set; if so, I return that field, otherwise I return the Published Date field. They all fail in various ways. Most throw PHP errors that are visible even to anonymous users (obviously a problem).

我已经在Views的Sort Criterial部分直接尝试了这些各种方法;我也试图在字段部分中提出日期,然后获得结果的排序标准调用。我已将所有内容转换为Unix时间戳,以确保我有一些简单的排序方式;我已经尝试将日期作为日期。没有运气。

I have tried these various approaches directly in the Sort Criterial section of Views; I've also tried to come up with the date in the Fields section, and then have a Sort criterion call that result. I've converted everything to a Unix timestamp, to make sure I have something simple to sort by; I've tried leaving dates as dates. No luck any which way.

这里是真正的奇怪的部分:我已经成功地使用这些方法来显示正确的日期,以便(例如)块显示•TITLE |自定义内容类型的原始日期,以及•TITLE |饲料项目的发布日期。但是,当我按照同样的方式按日期排序时,它会失败。

Here's the really weird part: I have successfully used these approaches to display the correct date, so that (for example) the block shows • TITLE | Original Date for custom content types, and • TITLE | Published Date for feed items. But when I try the same approach(es) to sort by date, it fails.

我是否俯视更简单?我必须使用PHP视图吗?有没有其他方法可以通过两种不同(但类似的)字段的组合对多种内容类型进行查看?

Am I overlooking something simpler? Do I have to use PHP Views? Is there some other way to sort a View of multiple content types by a combination of two different (though similar) fields?

谢谢!

tf

推荐答案

您是否尝试使用视图的关系功能?您可以使用它来访问所有内容类型的所有日期字段,然后添加一些条件代码到字段项,你应该是黄金。 (也就是说,如果我正确理解问题...)

Have you tried using the relationship feature of views? You could use that to get access to all of the date fields of all of the content types, then add some conditional code to the field item and you should be golden. (That is, if I'm understanding the question correctly...)

这篇关于Drupal 7:在视图中排序多个内容类型,具有不同的日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆