动态查看drupal 7中的日期参数

时间:2011-12-22 03:45:13

标签: drupal-7 drupal-views

我是drupal的新手,目前我遇到了这个问题。

我想创建一个文章视图(“当天的提示”),其中意志的内容会相应地自动更改。默认值为当前日期。

例如:

的http://本地主机/测试 这会将当前日期作为默认过滤器。如果没有找到任何物品,则不会发现任何结果。

当我转到 http:// localhost / test / 20111220 时,视图会自动获取网址中日期参数的值,并在该日期输出内容。

我怎样才能实现这个目标?

那里有什么想法或想法吗?

谢谢。

1 个答案:

答案 0 :(得分:6)

如果您使用的是视图,请尝试以下操作。

  1. 高级 字段集中添加 上下文过滤器 ,然后选择 日期:日期(节点) ) 过滤。
  2. 的设置中当过滤值不在网址 字段集中时,勾选 提供默认值 < / strong>并保留 当前日期
  3. 添加多个值标识符 设置为
  4. 要比较的日期 设置为 仅此字段
  5. 日期字段 复选框之间选择 内容:发布日期
  6. 方法 设置为
  7. 之后,通过访问 / test 页面,您将获得最后添加的内容,并访问 / test /%date% 您将拥有该日期的内容。例如 / test / 2011-12-23

    %date% 应为ISO日期/期间格式(即YYYY,YYYY-MM,YYYY-MM-DD,YYYY-W99,YYYY-MM- DD - P3M,P90D等。

    已编辑:19-01-2012

    在您的网站中按照此路径http://yoursite/admin/structure/views/import将以下数据放入代码文本字段:

    $view = new view;
    $view->name = 'test';
    $view->description = '';
    $view->tag = 'default';
    $view->base_table = 'node';
    $view->human_name = 'test';
    $view->core = 7;
    $view->api_version = '3.0';
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
    
    /* Display: Master */
    $handler = $view->new_display('default', 'Master', 'default');
    $handler->display->display_options['title'] = 'test';
    $handler->display->display_options['access']['type'] = 'perm';
    $handler->display->display_options['cache']['type'] = 'none';
    $handler->display->display_options['query']['type'] = 'views_query';
    $handler->display->display_options['query']['options']['query_comment'] = FALSE;
    $handler->display->display_options['exposed_form']['type'] = 'basic';
    $handler->display->display_options['pager']['type'] = 'some';
    $handler->display->display_options['pager']['options']['items_per_page'] = '10';
    $handler->display->display_options['style_plugin'] = 'list';
    $handler->display->display_options['row_plugin'] = 'fields';
    $handler->display->display_options['row_options']['hide_empty'] = 1;
    $handler->display->display_options['row_options']['default_field_elements'] = 0;
    
    /* No results behavior: Global: Text area */
    $handler->display->display_options['empty']['area']['id'] = 'area';
    $handler->display->display_options['empty']['area']['table'] = 'views';
    $handler->display->display_options['empty']['area']['field'] = 'area';
    $handler->display->display_options['empty']['area']['label'] = 'No results';
    $handler->display->display_options['empty']['area']['empty'] = FALSE;
    $handler->display->display_options['empty']['area']['content'] = 'No articles found.';
    $handler->display->display_options['empty']['area']['format'] = 'full_html';
    $handler->display->display_options['empty']['area']['tokenize'] = 0;
    
    /* Field: Content: Title */
    $handler->display->display_options['fields']['title']['id'] = 'title';
    $handler->display->display_options['fields']['title']['table'] = 'node';
    $handler->display->display_options['fields']['title']['field'] = 'title';
    $handler->display->display_options['fields']['title']['label'] = '';
    $handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
    $handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
    $handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
    $handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
    $handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
    $handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
    $handler->display->display_options['fields']['title']['alter']['trim'] = 0;
    $handler->display->display_options['fields']['title']['alter']['html'] = 0;
    $handler->display->display_options['fields']['title']['hide_empty'] = 0;
    $handler->display->display_options['fields']['title']['empty_zero'] = 0;
    $handler->display->display_options['fields']['title']['link_to_node'] = 1;
    
    /* Sort criterion: Content: 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';
    
    /* Contextual filter: Date: Date (node) */
    $handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
    $handler->display->display_options['arguments']['date_argument']['table'] = 'node';
    $handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
    $handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
    $handler->display->display_options['arguments']['date_argument']['default_argument_skip_url'] = 0;
    $handler->display->display_options['arguments']['date_argument']['summary']['format'] = 'default_summary';
    $handler->display->display_options['arguments']['date_argument']['use_fromto'] = 'no';
    $handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
        'node.created' => 'node.created',
    );
    
    /* Filter criterion: Content: 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;
    
    
    /* Filter criterion: Content: Type */
    $handler->display->display_options['filters']['type']['id'] = 'type';
    $handler->display->display_options['filters']['type']['table'] = 'node';
    $handler->display->display_options['filters']['type']['field'] = 'type';
    $handler->display->display_options['filters']['type']['value'] = array(
        'page' => 'page',
    );
    
    /* Display: Page */
    $handler = $view->new_display('page', 'Page', 'page');
    $handler->display->display_options['path'] = 'test';
    

    现在,通过关注/test页面,您将拥有今天的约会日期。您还可以将日期类型用作20120119