【问题标题】:Drupal: custom taxonomy page, exclude nodes with some taxonomy child (without views module)Drupal:自定义分类页面,排除带有一些分类子节点的节点(没有视图模块)
【发布时间】: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')

感谢您的帮助。

【问题讨论】:

    标签: drupal drupal-taxonomy


    【解决方案1】:

    当你说

    这行不行

    PHP 应用程序是否崩溃或者您没有得到预期的结果?

    这个查询逻辑好像很奇怪

    ->fieldCondition('field_category', 'tid', $term->tid , '=')
    ->fieldCondition('field_category', 'tid', array(135) , 'NOT IN')
    

    想象一下你的$term->tid = 1。您正在选择 field_category,其中 tid 为 1 AND $term->tid NOT IN (135)。这将为您提供附加到 1 个类别而不是多个类别的节点...这是您想要的吗?

    【讨论】:

    • 例如一些分类术语,如运动 - 足球(已选择)- 篮球(已选择)- 乒乓球(未选择)我想要运动分类页面,显示附加到运动(足球、篮球)的节点但不是乒乓球。
    猜你喜欢
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多