写在文章之前的一些话
建这个站点最初的计划是学习、收集、组织有关Drupal 6.x 的文章知识,然而我负责的一个网站还在使用Drupal 5.x 。虽然这个站点所应具备的功能全部实现了,网站也正常运行了几个月了,但是我还想为这个站点做第二次修改、优化。所以还要从新收集Drupal 5.x 以及 Drupal 5.x 相关模块的文章。由于中文文档资料很少,只得到 drupal.org 找了,英文水平太差,只有借助翻译软件,在 drupal.org 找资料就象大海捞针一样(有点夸张了),找到的资料文章也不敢独享,写出来或许能帮到别人,也能为自己方便以后参考。
这个 Drupal 5.x 站点有个分类,有10篇文章,后需要将这个分类下的文章划分成2块。
之前:
分类
|-- 文章1
|-- 文章2
...
|-- 文章10
之后:
分类
|-- 子分类一:
|--文章1
|--文章2
...
|--文章5
|-- 子分类二
|--文章1
|--文章2
...
|--文章5
当时的解决办法是,在分类下又增加2个子分类,把相应的文章转到该分类下,由于文章需要按特定的顺序排序,我又安装Node Queue模块。
用Node Queue模块建立2个队列,按照要求的顺序添加文章到各自的队列中,Node Queue模块会把这2个队列显示到区块列表中,
在template.php中增加一个自定regions:block_content
添加区块:1111让其显示在block_content
区块正文:
<div class="c-head"><h3>子分类一</h3></div>
<?php print nodequeue_nodes(1, $backward = FALSE, $teasers = true, $links = true, $from = 0, $count = 10) ; ?>
<div class="c-head"><h3>子分类二</h3></div>
<?php print nodequeue_nodes(2, $backward = FALSE, $teasers = true, $links = true, $from = 0, $count = 10) ; ?>
复制page.tpl.php为page-taxonomy-term-2.tpl.php
删除:
增加:
<?php if ($block_content): print $block_content; endif; ?>
一系列的工作,够复杂吧。
后来有些分类的文章又有增加,超过10篇了,原本一页可以显示node列表,现在需要翻页,控制每页显示node数是在“发布设置”里控制,是全局控制,一直没有找到个别控制的方法,烦恼又来了。经过研究发现了Weight模块,可以对node排序,真的很不错,对于这类超过10篇文章数量的分类列表页面,我通过Views模块调用,想显示几篇文章自己可以设定,排序交给Weight模块:Sort Criteria 添加Node: Sticky,ASC还是DESC自己决定。
一个个问题都解决了,现在回头看看,Node Queue模块可以退役了。
但是怎样用Views模块实现在一个页面分类列表显示各自的node还是需要多研究的。
http://drupal.org/node/42599 这里有个例子很不错
<?php
// load a second copy of the view -- unfortunate but we don't have access
// to the existing one.
$view = views_get_view('VIEWNAME');
// the array() indicates no arguments, which will provide the summary view.
// We also don't want the pager for this view.
print views_build_view('embed', $view, array(), false, false);
?>
这个方法可以在一个Views(页面或区块)的header或Footer插入另一个Views。
上面代码中
$view = views_get_view('VIEWNAME');
VIEWNAME就是你的Views的名字
还有一些例子:
<?php
// This is a new variable introduced in Views module revision v.1.94;
// it conveniently gives one access to the current view (in this example, view 1)
global $current_view;
// Let's now load view 2
$view = views_get_view('VIEW2NAME');
// $current_view->args contains the arguments view 1 is currently being provided with;
// we can now build view 2 with exactly the same arguments as view 1
print views_build_view('embed', $view, $current_view->args, false, false)
?>
<?php
// This loads all the variables of the primary view,
// including arguments which are in $current_view->args
global $current_view;
// Now let's call ALL desired additional views for this (you can add more
// if desired, just make sure to give each a unique variable name.
$view_1 = views_get_view('home_page_new_groups');
$view_2 = views_get_view('home_page_popular_groups');
$view_3 = views_get_view('home_page_new_content');
// This is some structuring HTML
print t("<br />");
print t("<h2>Newest Groups</h2>");
// Build and print the view: first tell Views to embed the next view,
// then tell the function WHICH view you mean (you have defined
// this in the variables $view_1, $view_2 and $view_3 above.
// Next, pass into these views the Arguments from the primary view
// which you retrieved with global $current_view; and last but not
// least, "true, 10" enables paging and pages after 10 nodes are listed -
// change this number to whatever you need.
// So let's start outputting the first view:
print views_build_view('embed', $view_1, $current_view->args, true, 10);
// This is again some structuring HTML
print t("<p> </p>");
print t("<h2>Most Popular Groups</h2>");
// Build and print the next view
print views_build_view('embed', $view_2, $current_view->args, true, 10);
// This is again some structuring HTML
print t("<p> </p>");
print t("<h2>Most Popular Groups</h2>");
// Build and print the next view
print views_build_view('embed', $view_3, $current_view->args, true, 10);
// Continue adding views if you have set them up and assigned a
// unique variable above
?>
还有:
http://drupal.org/node/85720
Views 1.x module developer API
最新评论
3 周 3 天之前
6 周 4 天之前
15 周 3 天之前
15 周 4 天之前