Help with a next/previous item view.

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by wipeout_dude on May 19, 2012 at 11:32am

Hi,

I have to add a new feature to a site.. Basically there is a "schedule" content type with week commencing field.. What they want to achieve is a the ability to go to the "next week" or the "previous week" easily without doing back to the main view of "all weeks"..

My initial thought was that this could be done with a view as a block showing three successive weeks with the currently viewed week in the middle.. While this wouldn't be a next/previous as such it would provide the required functionality..

Problem is I can't work out how to get it to work..

Anyone have any ideas?

Comments

And, you are choosing to not

Posted by greta_drupal on May 21, 2012 at 3:40am

And, you are choosing to not use Calendar module, which has this feature built-in, why?

Because the customer

Posted by wipeout_dude on May 21, 2012 at 6:37am

Because the customer specifically didn't want a calendar.. They simply wanted a single content type with the fields "Week Commencing", "Monday", "Tuesday", "Wednesday", "Thursday" and "Friday".. All on one page to mimic the paper based system they are used to..

Now they want to switch between "weeks" from the node itself without going back to the list view.. So I figured a view in a block would be the way to achieve it but not sure how to get "the one before the current one and the one after the current one"..

Filtering + ordering

Posted by joelwallis on May 21, 2012 at 10:31am

I think listing is the enough solution to this. Have you tried to show only nodes with a date filter (only nozes created until the current node publishing date, ordering with desc and showing the first one.

The next can usee with the same technique.

@joelwallis - That what I had

Posted by wipeout_dude on May 21, 2012 at 2:03pm

@joelwallis - That what I had in mind but I can't use the "published" date I have to use the date specified in the "Week Commencing" field..

I am not sure how to tell views to only show me other nodes of the same content type that have a value in the "week commencing" field that is higher or lower than the value in the "week commencing" field of the currently viewed node..

Contextual filters appear to limit the view to showing only the node being viewed (as it should) but with no way to then get the next or previous based on the week commencing field of the viewed node..

You should use ordering +

Posted by joelwallis on May 21, 2012 at 5:00pm

You should use ordering + filtering. It should be in two displays. one showing the revious and another to show the next

Hi, Thanks, that part I

Posted by wipeout_dude on May 21, 2012 at 5:13pm

Hi,

Thanks, that part I understand..

What I don't seem to be able to find in how to filter the view to show items with earler or later dates (depending on the display) relative to the field containing a date in the currently viewed node?

Attachment view to the rescue?

Posted by databoy on May 21, 2012 at 5:23pm

I think what you want is to be able to get info from an attachment view, like this: http://drupaleasy.com/blogs/ultimike/2009/07/using-views-relationships-a... or something like this: http://drupal.org/node/662362 which is a patch/module combo...

Or, use the Calendar module, but without, you know, the actual calendar?

Good luck!

Just had a play with getting

Posted by wipeout_dude on May 21, 2012 at 6:06pm

Just had a play with getting the calendar module to do it but still no luck I'm afraid..

Everything allows sorting of the view relative to a predefined date or a relative date from "now".. There doesn't appear to be a way to sort relative to a date field in the currently viewed node..

Did you solve it?

Posted by jaimeah on August 9, 2012 at 12:02am

It is haarder than it seems isn't it? Did you get to a solution?

Unfortunately I didn't find a

Posted by wipeout_dude on August 9, 2012 at 7:13am

Unfortunately I didn't find a way to sort the view relative to the date in a field.. I ended up just giving them a general list in a block that they can page through.. Its not a permanent fix because as the number of recorded "weeks" grows it will become a little cumbersome but I will look at it again then.. :)

Create a module

Posted by kelvinleehk on August 9, 2012 at 8:24am

I too ran into a problem trying to do something similar, at the end I gave up looking for a UI way to do the job and just created a module for that. Turned out it wasn't so bad :)

I'd basically do the following:
1. Create a view that takes a date (e.g. first day of the week) as parameter.
2. Create a module that:
- define a block
- create a function that query and calculate the first day of previous week and next week.
- define the block content, with a PREVIOUS and a NEXT link where URL points to the view you created in #1, with the first day of previous week and next week as the parameters (appended at the end of URL) respectively.

The rest is just to decide where to put the block and theming.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /