【发布时间】:2023-04-03 12:53:01
【问题描述】:
我有一个新闻聚合器项目。 在这个项目中,我有这样的类别。
-
运动
- 运动:足球(打勾)
- 运动:篮球(打勾)
- 运动:排球
- 运动:网球
-
政治
- politic:你的国家(打勾)
- 政治:其他
上面的树显示用户希望如何聚合新闻。
我将数据库中每个用户的所有选定和未选定分类法保存在两个不同的变量中作为数组宽度函数variable_set
现在我想在运动分类页面,默认drupal页面,只显示足球和篮球是他们的类别的节点,网球和排球的节点不会显示。
我的意思是覆盖默认分类页面的行为。 我知道这可能发生在 views 模块 buttttt 分类数不固定。在新闻聚合网站的生命周期中,它将越来越多。现在它们的数量已经超过 340 个分类法。
现在我已经编写了这段代码。这段代码。此代码运行良好,但我想在父分类页面中,节点显示用户收集了他们的子分类。
function caspian_bartik_menu_alter(&$menu) {
$menu['taxonomy/term/%taxonomy_term']['page callback'] = 'caspian_bartik_term_page';
$menu['taxonomy/term/%taxonomy_term']['access arguments'] = array('access content');
$menu['taxonomy/term/%taxonomy_term']['page arguments'] = array(2);
}
function caspian_bartik_term_page($term){
$voc = taxonomy_vocabulary_load($term->vid);
// here you generate the actual content of the page
// could be done e.g. with an entityfieldquery as follows
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->fieldCondition('field_category', 'tid', $term->tid , '=')
->fieldCondition('field_category', 'tid', array(135) , 'NOT IN')
->propertyOrderBy('created', 'DESC');
$result = $query->execute();
if (!empty($result['node'])) {
$build['content']['nodes'] = node_view_multiple(node_load_multiple(array_keys($result['node'])), 'teaser');
} else {
$build['content']['status']['#markup'] = t('No results found for term ID !tid.', array('!tid' => $term->tid));
}
return $build;
}
这行不行
->fieldCondition('field_category', 'tid', array(135) , 'NOT IN')
感谢您的帮助。
【问题讨论】: