小编JR.*_*JR.的帖子

Drupal:如何以编程方式为已在节点保存上具有别名的节点创建URL别名?

我有一个自定义模块,它实现了hook nodeapi,以便在创建或更新节点时执行某些代码.

基本上我想基于节点保存或更新时自动生成的别名创建别名.

现在我正在使用对path_set_alias的调用,我只想用特定类型的内容"product"来做这件事.

这是我的nodeapi电话,让我开始

function product_url_helper_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {

 if($node->type == 'product'){
  switch($op){

     case 'insert':
      _create_alternate_url($node);

     break;

     case 'update':
      _create_alternate_url($node);
     break;

     case 'view':
       //do nothing
     break;

  default:
  break;

  }
 }

 return;
}
Run Code Online (Sandbox Code Playgroud)

然后我有这个功能,我正试图为我保存我的第二个URL别名.

function _create_alternate_url($node){
$aliasExists = db_fetch_object(db_query("SELECT count(dst) as total FROM {url_alias} WHERE dst = 'alternate/".$node->path."'"));
if($aliasExists->total == 0){

    $product_url = $node->path;
 $alternate_url = "alt/" . $node->path;
 $default_node_path = "node/" . $node->nid;

    path_set_alias($default_node_path, $alternate_url, 0, '');

  drupal_set_message("Created Alternate path for Product: " . …
Run Code Online (Sandbox Code Playgroud)

drupal

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

drupal ×1