根据分类术语生成URL别名

Jam*_*kby 3 drupal drupal-7 drupal-taxonomy drupal-modules

我有一个词汇类别,里面有四个术语.我想要做的是,如果内容被标记为一个终端,特别是说"term1",将url生成为word1/[node:title],而所有其他标签只是标准的url格式.

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

scr*_*ide 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;
}
Run Code Online (Sandbox Code Playgroud)