Php 德鲁帕尔。获取模板中的筛选节点
在Drupal7中,如何在页面模板中获得基于特定过滤器的节点列表?例如,page--popular.tpl.php 例如,获取内容类型为“article”且分类名称为“news”的最新4个节点 我知道大多数人是在“观点”中这样做的,但我有理由不能这样做Php 德鲁帕尔。获取模板中的筛选节点,php,drupal,drupal-7,drupal-theming,Php,Drupal,Drupal 7,Drupal Theming,在Drupal7中,如何在页面模板中获得基于特定过滤器的节点列表?例如,page--popular.tpl.php 例如,获取内容类型为“article”且分类名称为“news”的最新4个节点 我知道大多数人是在“观点”中这样做的,但我有理由不能这样做 如果有人能帮忙,我将不胜感激 页面模板包含区域,尤其是已呈现的内容区域。所以,我想,您的问题必须正确地表述如下:“如何在不使用视图的情况下创建包含节点列表的自定义页面”。为此,您需要在模块中实现hook_菜单: /** * Implements
如果有人能帮忙,我将不胜感激 页面模板包含区域,尤其是已呈现的
内容
区域。所以,我想,您的问题必须正确地表述如下:“如何在不使用视图的情况下创建包含节点列表的自定义页面”。为此,您需要在模块中实现hook_菜单
:
/**
* Implements hook_menu().
*/
function mymodule_menu() {
$items = array();
$items['popular'] = array(
'title' => 'Popular articles',
'page callback' => '_mymodule_page_callback_popular',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Page callback for /popular page.
*/
function _mymodule_page_callback_popular() {
$news_tid = 1; // This may be also taken from the URL or page arguments.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', NODE_PUBLISHED)
->fieldCondition('field_taxonomy', 'tid', $news_tid) // Use your field name
->propertyOrderBy('created', 'DESC')
->range(0, 4);
$result = $query->execute();
if (isset($result['node'])) {
$node_nids = array_keys($result['node']);
$nodes = entity_load('node', $node_nids);
// Now do what you want with loaded nodes. For example, show list of nodes
// using node_view_multiple().
}
}
查看和。页面模板包含区域,尤其是已呈现的
内容区域。所以,我想,您的问题必须正确地表述如下:“如何在不使用视图的情况下创建包含节点列表的自定义页面”。为此,您需要在模块中实现hook_菜单
:
/**
* Implements hook_menu().
*/
function mymodule_menu() {
$items = array();
$items['popular'] = array(
'title' => 'Popular articles',
'page callback' => '_mymodule_page_callback_popular',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Page callback for /popular page.
*/
function _mymodule_page_callback_popular() {
$news_tid = 1; // This may be also taken from the URL or page arguments.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', NODE_PUBLISHED)
->fieldCondition('field_taxonomy', 'tid', $news_tid) // Use your field name
->propertyOrderBy('created', 'DESC')
->range(0, 4);
$result = $query->execute();
if (isset($result['node'])) {
$node_nids = array_keys($result['node']);
$nodes = entity_load('node', $node_nids);
// Now do what you want with loaded nodes. For example, show list of nodes
// using node_view_multiple().
}
}
看看并解释你的“理由”。解释你的“理由”。