Help with a next/previous item view.

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
wipeout_dude's picture

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

greta_drupal's picture

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

Because the customer

wipeout_dude's picture

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

joelwallis's picture

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

wipeout_dude's picture

@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 +

joelwallis's picture

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

wipeout_dude's picture

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?

databoy's picture

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

wipeout_dude's picture

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?

jaimeah's picture

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

Unfortunately I didn't find a

wipeout_dude's picture

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

kelvinleehk's picture

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.