Archive block should show most recent month first. Somehow it doesn't. I just reverted/reseted the view. Sort order is desc which is correct, but list items show oldest month first. Nothing changes when I set the sort order to asc.

Continuing from http://drupal.org/node/317395. New issue for new version as suggested.

CommentFileSizeAuthor
#8 Picture 8.png96.57 KBegrotke
#4 archive-default-order.patch477 bytesmokko

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Did you changed the summary order? This can be done in the argument.

$view = new view;
$view->name = 'archive';
$view->description = 'Display a list of months that link to content for that month.';
$view->tag = 'default';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['title'] = 'Monthly archive';
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* Sort criterion: Node: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Argument: Node: Created year + month */
$handler->display->display_options['arguments']['created_year_month']['id'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['table'] = 'node';
$handler->display->display_options['arguments']['created_year_month']['field'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['default_action'] = 'summary asc';
$handler->display->display_options['arguments']['created_year_month']['style_plugin'] = 'default_summary';
$handler->display->display_options['arguments']['created_year_month']['style_options']['override'] = TRUE;
$handler->display->display_options['arguments']['created_year_month']['style_options']['items_per_page'] = '30';
$handler->display->display_options['arguments']['created_year_month']['title'] = '%1';
$handler->display->display_options['arguments']['created_year_month']['default_argument_type'] = 'fixed';
/* Filter: Node: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'archive';

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Argument: Node: Created year + month */
$handler->display->display_options['arguments']['created_year_month']['id'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['table'] = 'node';
$handler->display->display_options['arguments']['created_year_month']['field'] = 'created_year_month';
$handler->display->display_options['arguments']['created_year_month']['default_action'] = 'summary asc';
$handler->display->display_options['arguments']['created_year_month']['style_plugin'] = 'default_summary';
$handler->display->display_options['arguments']['created_year_month']['style_options']['items_per_page'] = '30';
$handler->display->display_options['arguments']['created_year_month']['title'] = '%1';
$handler->display->display_options['arguments']['created_year_month']['default_argument_type'] = 'fixed';
$handler->display->display_options['block_description'] = 'Archive list';
mokko’s picture

Status: Postponed (maintainer needs more info) » Active

BTW: When I create a new display for the same view (block) the sort order is correct (desc), but I cannot limit the number of displayed items.

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Change back the issue state, I hope this is fine :)

What happens if you set the pager settings, if this does not work it's a feature request :)

mokko’s picture

StatusFileSize
new477 bytes

Thanks for a very good answer! I am still new to arguments and didn't know about sorting arguments yet! It works fine now on that site.

Now, I am trying to find out if the default setting is wrong. So I go to different project, activate archive view and look at the various preview displays. Default and page show most recent month first, but block does not. I consider this a wrong default.

In case you want a patch, I attach one.

This is the view directly exported after enabling

$view = new view;
$view->name = 'archive';
$view->description = 'Display a list of months that link to content for that month.';
$view->tag = 'default';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('sorts', array(
  'created' => array(
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'order' => 'DESC',
    'granularity' => 'second',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'created_year_month' => array(
    'id' => 'created_year_month',
    'table' => 'node',
    'field' => 'created_year_month',
    'default_action' => 'summary desc',
    'style_plugin' => 'default_summary',
    'style_options' => array(
      'count' => 1,
      'override' => 1,
      'items_per_page' => '30',
    ),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '%1',
    'relationship' => 'none',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'default_argument_type' => 'fixed',
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'operator' => '=',
    'value' => 1,
    'group' => 0,
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Monthly archive');
$handler->override_option('use_pager', '1');
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
  'teaser' => TRUE,
  'links' => TRUE,
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'archive');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler = $view->new_display('block', 'Block', 'block');
$handler->override_option('arguments', array(
  'created_year_month' => array(
    'id' => 'created_year_month',
    'table' => 'node',
    'field' => 'created_year_month',
 
   'default_action' => 'summary asc', <------------

    'style_plugin' => 'default_summary',
    'style_options' => array(
      'count' => 1,
      'override' => 0,
      'items_per_page' => '30',
    ),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '%1',
    'relationship' => 'none',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'default_argument_type' => 'fixed',
  ),
));
$handler->override_option('block_description', 'Archive list');
$handler->override_option('block_caching', -1);
mokko’s picture

Status: Postponed (maintainer needs more info) » Patch (to be ported)

not sure which status

merlinofchaos’s picture

Status: Patch (to be ported) » Closed (won't fix)

No, I'm not changing the default. There are hundreds of thousands of sites running Views. Surely some percentage of them are using the archive view with defaults, and this patch would change their sites when they update without any explanation. Maybe for some or many that's actually what they wanted, but it would not be true for all.

ao2’s picture

For those who still want this change without applying any patches, it can be done from the UI. This was suggested by Jake in a comment here: http://chrisshattuck.com/blog/how-create-monthly-archive-block-drupal-bl...

Step-by-step instructions:

  • Go to admin/build/views/edit/archive
  • Select the block display
  • Click to edit the argument Node: Created year + month
  • in the Action to take if argument is not present: options select Summary, sorted descending
  • Update and Save

Regards,
Antonio

egrotke’s picture

StatusFileSize
new96.57 KB

I've been staring at this for a while and I don't see the option for step 4 here:
"in the Action to take if argument is not present: options select Summary, sorted descending"

I'm in Drupal 6.2, on Edit view archive page.
What am I missing?

Thanks for any help!
-Eric

merlinofchaos’s picture

It's in the argument settings.

paultrotter50’s picture

Issue summary: View changes

I found that disabling the pager was a quick fix for this

paultrotter50’s picture

I found that disabling the pager was a quick fix for this

darnit78’s picture

I'm using Drupal 7. To help others, I'll mention the Drupal 7 way to implement 'ao2' suggestion.

While editing the view (mine was a block), open the Advanced section, and click on "Content: Created year + month" under CONTEXTUAL FILTERS. You'll find a sort order set of checkboxes there. I changed mine to Descending to cause the most recent month to display at the top of the list.

web506’s picture

Thank you darnit78 , that worked!

ao2’s picture

And for the record the same thing applies to Drupal 8.

It's a standard behavior of Views, which an be easily overlooked, or forgotten. Maybe the issue is exacerbated by and the fact that the Advanced fieldset is collapsed by default.

The instructions from #12 work for D8 too.

The confusion arises from the fact that when CONTEXTUAL FILTERS are used, and When the filter value is NOT available is set to Display a summary, the summary sorting behavior overrides the general Sort criteria of the view.

I keep the two sorting settings equal to have a more consistent behavior.