Cấu hình Views làm việc Correctly Display Repeating Date Fields

Cấu hình Views làm việc Correctly Display Repeating Date Fields

Configuring Views and Date is a simple enough task for any reasonably experienced site builder, but I’ve found that configuring Views to correctly handle and display repeating events is another matter. To get us started, I’ve installed the following modules: 

- Views Views UI

- Date  Date Repeat Field, Date Views

I created a content type called “Event”. The next step is to add and configure a Date field. While configuring, make sure you set “Repeating Date” to “Yes”. 

The rest of the settings are more or less up to you depending on your needs, but if you’re not sure, the defaults should be fine. You’ll notice that the “Number of Values” setting is grayed out. This is because repeating Date fields required Unlimited values.

Now that your Date field has been configured, create a piece of test content. This will come in handy while you’re building your View. Any sort of repeating event will do. For this example, I’ll be using an event that repeats on the second Thursday of each month for the next three years.

Now that we have some content to work with, we can create our view. This view will have one Page type display, showing content of the Event type as an unformatted list of fields. Generally, the first thing you will want to do is add a filter to the view to prevent it from showing past events. If you do want past events to be shown, skip this section, otherwise, add a new filter for the Date field on your Event content type. If you chose to use a Date field with both a Start and End date, you’ll want to select the Start date for the filter.

Generally, I prefer Minute granularity, and you must select “Yes” for “Add multiple value identifier”. Next, set the filter itself to “greater than or equal to” and a relative time of “now”.

Cấu hình Views làm việc Correctly Display Repeating Date Fields

Now your view will only display current and future events. With the addition of this filter, the single event in your preview should have changed to multiple events. The next step: adding and configuring the Date field itself.

The settings for the Date field are fairly simple. In most cases, you’ll want to hide the repeat rule. However, you must uncheck “Display all values in same row” under “Multiple field settings”, or the view will not correctly display the dates.

The resulting view should be a perfectly serviceable list of your upcoming events. However, there is one optional extra step: for a given event, only displaying the next occurrence, not any past occurrences or more than one future occurrence. To do this, you’ll need to enable two settings under the Advanced tab on the right. The first is Aggregate, which is under the “Use aggregation” option. 

The second option we need to enable is Distinct, which is under the “Query settings” option:

This, combined with the filter we made earlier, will cause your view to display only the next upcoming event for a recurring event series. And with that, you’re done: your view now displays recurring date fields correctly.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Keep your website crawl error free using these modules

Keep your website crawl error free using these modules

Crawl errors are the bane of every digital marketer-- they seemingly pop up over night and their numbers grow exponentially. Luckily for Drupal marketers there a number of techniques that you can employ to minimize the number of crawl errors that occur and fix the newly created crawl errors on your website.

Dùng Facebook để quảng cáo, tiếp thị trực tuyến

Dùng Facebook để quảng cáo, tiếp thị trực tuyến

Khi quyết định sử dụng một kênh quảng cáo tiếp thị nào, ta cần phải đánh giá hiệu quả thu được dự kiến dựa trên các con số thực tế. Bài viết này sẽ đưa ra một số thông tin cụ thể hơn nhằm giúp các bạn nắm được các thông tin cơ bản về lượng người dùng của Facebook.

Làm việc với Drupal 8 Block Cache năm 2016

Làm việc với Drupal 8 Block Cache năm 2016

In case you've had trouble tracking it down (I did), the approach to caching custom blocks is different in Drupal 8 than in Drupal 7

Công ty diệt chuột T&C

 

Diet con trung