【问题标题】:Trying to insert taxonomy term from view into page title on Drupal 7 site尝试将分类术语从视图插入 Drupal 7 站点的页面标题
【发布时间】:2014-05-21 04:43:55
【问题描述】:

我的网站上有许多使用分类术语作为上下文过滤器的视图。我正在尝试将该分类术语添加到页面标题中。

'Latest TAXONOMY_TERM News | Sitename etc.'

我在我的 template.php 中的 THEME_views_post_render 函数中使用 taxonomy_term_load 来获取术语并构建页面标题。然后,我将此变量传递给 THEME_preprocess_html,并在其中使用它来覆盖 $variables['head_title']。

views_post_render:

$term = taxonomy_term_load($view->result[0]->_field_data['nid']['entity']->field_term['und'][0]['tid']);

$page_title = 'Latest ' . $term->name . ' News | ' . variable_get('site_name', 'Sitename etc');

preprocess_html:

$variables['head_title'] = $page_title ;

如果我回显 $variables['head_title'] 我可以看到我在 THEME_views_post_render 中定义的页面标题,但它显然缺少分类术语。

'Latest News | Sitename etc.'

任何人都可以对这里发生的事情有所了解吗?我确实考虑过在 THEME_preprocess_html 函数中执行所有逻辑,但这似乎无法访问视图。

感谢任何帮助。

罗伯。

【问题讨论】:

    标签: php drupal drupal-7


    【解决方案1】:

    在视图标题中,您可以使用将显示术语名称的替换模式。使用它您可以设置所需的页面标题。

    【讨论】:

      【解决方案2】:

      您没有提供如何在代码 sn-p 中计算/填充 $view 变量。首先确保你做对了。我还建议使用Devel 模块的dpm 功能(或其朋友),而不是使用 echo 进行调试。

      【讨论】:

        猜你喜欢
        • 1970-01-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
        相关资源
        最近更新 更多