0

I am using D6. I want to create a views with date field using in a content type such as "Photo Gallery". What i have done are:-

  1. In argument, select Content: Date (Date Appears in: Photo Gallery) then
  2. select granularity as "year", sorted descending, check "Content:Date
  3. save it.
  4. I separately do for both month and day respectively.

What i am getting in URL are like photo-gallery/2010, photo-gallery/2010/2010-10, photo-gallery/2010/2010-10/2010-10/10 for year, month, day respectively.

But i don't want this.

I want Url like for year- photo-gallery/2010, for month- photo-gallery/2010/10 and for day-photo-gallery/2010/10/10 I am stuck here. So how can i do this?

  • This should rather be a feature request for a Date module. But it will not happen. Drupal 6 will be out of support really soon, and feature requests will be moved to 7.x or 8.x branch of a module. – Mołot Jan 4 '14 at 8:12
0

You should be able to do something along these lines in a custom module if the out of the box Date and Views modules don't do it:

First off, create all your Views as Block Displays (eg, not Page Displays with a path defined by Views) with the various arguments in place. For ease of discussion later on, let's say the View is called photo_gallery with displays of year, month and day.

Then, in your module, define the paths you want, eg:

function YOURMODULE_menu() {

  $items=array();

  $items['photo-gallery/%'] = array(
    'title' => 'Photos By Year',
    'page arguments' => array(1),
    'page callback' => 'YOURMODULE_photos_by_year',
    'access callback' => TRUE, 
  );

  $items['photo-gallery/%/%'] = array(
    'title' => 'Photos By Year/Month',
    'page arguments' => array(1, 2),
    'page callback' => 'YOURMODULE_photos_by_year_month',
    'access callback' => TRUE, 
  );

  $items['photo-gallery/%/%/%'] = array(
    'title' => 'Photos By Year/Month/Day',
    'page arguments' => array(1, 2, 3),
    'page callback' => 'YOURMODULE_photos_by_year_month_day',
    'access callback' => TRUE, 
  );

  return $items;

}

And then for your callbacks, you embed the view you want using the argument styles it wants, which would probably be something like this:

function YOURMODULE_photos_by_year($year) {

  return views_embed_view('photo_gallery', 'year', $year); // eg 2014

}

function YOURMODULE_photos_by_year_month($year, $month) {

  return views_embed_view('photo_gallery', 'month', $year . '-' . $month); // eg 2014-01

}

function YOURMODULE_photos_by_year_month_day($year, $month, $day) {

  return views_embed_view('photo_gallery', 'day', $year . '-' . $month . '-' . $day); // eg 2014-01-04

}

Now the above is all pretty broad strokes typed in directly (typos may abound) and not actually tested (I don't really know the exact format of the dates your Views arguments should be in) but should get you on your way. Things to keep in mind are argument validation (eg photo-gallery/notayear/notamonth/notaday) and paging of results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.