1

By default the "Archive" views module displays the dates as "May 2011." I want to change them to "2011 year May."

How do I do that? Is it possible?

from the instructions of googletorp: i made the following but it's not work. what's wrong with my code?

  1. created a module named customviews. which have files(customviews.info, customviews.module, customviews.views.inc)

  2. customviews.module has code:

        <?php
          function customviews_views_api(){
            return array('api'=>2);
          }
    

    function customviews_views_data_alter(&$data) { // Set the argument to the handler you named above. $data['node']['created_year_month']['argument']['handler'] = 'custom_handler'; }

  3. customviews.views.inc has code

     <?php
       class custom_handler extends views_handler_argument_node_created_year_month {
         function construct() {
           parent::construct();
           $this->format = "Y year M month"; 
         }
       }
    

i have cleared the cache.

i put the function customviews_views_data_alter(&$data) into the .module file. it's still can't work. what's wrong with it?

1

Views haven't supplied an easy way of doing this, but it is possible. To do this you would have to create your own handler and make views use that:

1. Creating own handler

class custom_handler extends views_handler_argument_node_created_year_month {
  function construct() {
    parent::construct();
    $this->format = 'F Y'; // Write your custom format here.
  }
}

2. Making view use your custom format

function module_name_views_data_alter(&$data) {
  // Set the argument to the handler you named above.
  $data['node']['created_year_month']['argument']['handler'] = 'custom_handler';
}

Update.

  1. The custom_handler class or whatever you choose to call it need to go in it's own file. For Drupal 7 the standard is to put it in a dir called handlers which is located in the dir that you specify with hook_views_api, and add the file as include in the .info file (Look at the views module for reference).
  2. For the module_name_views_data_alter you need to replace module_name, with the name of your module.
  3. Clear cache.
  • i am sorry, i put your code into my customed module. the data format wasn't changed. thank you. i researched this question a whole day.. i am new of object programme. could you give some explaination to your code? many thanks – enjoylife May 31 '11 at 2:23
  • i only changed your code $this->format = 'F Y'; to $this->format = 'F year Y month '; – enjoylife May 31 '11 at 2:25
  • it shows broken/missing handler on the views archive block setting page – enjoylife May 31 '11 at 3:19
  • i am sorry,i do it again. it invoke all the article title and content at the archive block part,i put the ways which i did on my questions. what's wrong with it? – enjoylife May 31 '11 at 11:06
  • i am sorry, i am not able to edit the code. the format is bad in the question – enjoylife May 31 '11 at 11:15

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.