drupal 7中按日期参数动态查看 [英] dynamic view by date arguments in drupal 7

查看:16
本文介绍了drupal 7中按日期参数动态查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 drupal 新手,目前遇到这个问题.

I'm new to drupal, currently im stuck with this problem.

我想创建一个文章视图(每日提示"),其中将自动更改内容.默认值为当前日期.

I want to create a article view ("tip of the day") wherein the content of the will automatically changed accordingly. The default value would be the current date.

例如:

http://localhost/test这将获取当前日期作为默认过滤器.如果没有找到任何项目,它将不会给出任何结果.

http://localhost/test this will get the current date as the default filter. If no items found it will give no results found.

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

when i go to http://localhost/test/20111220 the view will automatically get the value of the date parameter in the url and output the content on that date.

我怎样才能做到这一点?

How can I achieved this?

有什么想法或想法吗?

谢谢.

推荐答案

如果您使用的是 Views,请尝试以下操作.

If you are using Views then try the following.

  1. 高级字段集中添加上下文过滤器并选择日期:日期(节点) 过滤器.
  2. 在其设置中当过滤器值不在 URL 中时 字段集勾选 提供默认值 和离开当前日期
  3. 添加多值标识符设置为
  4. 要比较的日期设置为仅此字段
  5. 日期字段复选框之间选择内容:发布日期
  6. 方法设置为OR

之后,通过访问您的 /test 页面,您将获得最后添加的内容,并通过访问 /test/%date% 你会有那个日期的内容.例如 /test/2011-12-23

After that, by accessing your /test page you would have the last added content and by accessing /test/%date% you would have content for that date. For example /test/2011-12-23

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

%date% should be as ISO date/period format (i.e. YYYY, YYYY-MM, YYYY-MM-DD, YYYY-W99, YYYY-MM-DD--P3M, P90D, etc).

2012 年 1 月 19 日

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

Follow this path http://yoursite/admin/structure/views/import in your site and put the following data to code textfield:

$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.

Now by following to /test page you'll have date as today's date. You can also use your date type as 20120119.

这篇关于drupal 7中按日期参数动态查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆