3

我有一个词汇类别和四个术语。我想要做的是,如果内容被标记为特别是“term1”以使 url 生成为 word1/[node:title],而对于所有其他标签,则只是标准的 url 格式。

如果我想要 url 中的术语显然 id 使用模式替换,但如果使用特定标签,我希望使用另一个词

4

2 回答 2

5

我想不出一种简单的即插即用方式来实现这一目标。您可能必须在 Pathauto 的 URL 别名设置中为“默认路径模式”创建自己的令牌:

/**
 * Implementation of hook_token_info().
 */
function MODULE_token_info() {
  $info['tokens']['node']['node-term-path'] = array(
    'name'        => t('Node path by term'),
    'description' => t('The path to a node based on its taxonomy terms.'),
  );
  return $info;
}

/**
 * Implementation of hook_tokens().
 */
function MODULE_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'node' && !empty($data['node'])) {
    $node = $data['node'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'node-term-path':
          $items = field_get_items('node', $node, 'TAXONOMY_FIELD_NAME');
          foreach ($items as $item) {
            $tids[] = $item['tid'];
          }
          if (in_array(TID_OF_TERM1, $tids)) {
            // Path for nodes with term1
            $replacements[$original] = 'word1/'. pathauto_cleanstring($node->title);
          }
          else {
            // Path for other nodes
            $replacements[$original] = 'content/'. pathauto_cleanstring($node->title);
          }
          break;
      }
    }
  }
  return $replacements;
}
于 2012-07-09T18:18:16.133 回答
0

找到了一种简单的方法,任何需要类似解决方案的人都可以使用模块实体参考。

http://drupal.org/project/entityreference

我刚刚为用户帐户选择实体引用创建了一个新字段,然后您可以选择 drupal 中的任何实体进行引用。(即你可以选择一个术语/内容/任何东西)

于 2012-07-17T14:34:24.553 回答