用户工具

站点工具


drupal:script:title

Drupal 中修改标题栏 title

<?php
 
function gdh_get_node_title() {
  $node_title = "";
  if (arg(0) == "node" && is_numeric(arg(1)) ){
    //================ node page ========================
    $nid = arg(1);
    $node = node_load($nid);
    // global $node;
    $vid = "1";  // vid ==1 --> stort name vacabulary
    // $terms = taxonomy_node_get_terms_by_vocabulary($node, $vid);
    $node_title = $node->title;
    $tterms = $node->taxonomy;
    foreach ($tterms as $key => $tterm) {
      if ($tterm->vid == "1") {
        $node_title .= "_" . $tterm->name . "优惠券"; 
      } 
    }
    $node_title .= "_购物网站";
  }
  return $node_title;
}
 
function gdh_get_shopname_title() {
  $title = "";
  if ( arg(0) == "taxonomy" && arg(1) == "term" && is_numeric(arg(2)) ) {
    //================ signle term page ===============
    $tid = arg(2);
    $tterm = taxonomy_get_term($tid);
    #var_dump($tterm);
    if($tterm->vid == "1") { //$tid == 1 --> store name
      // echo $tterm->name . "youhuiquan\n";
      $title = $tterm->name . "优惠券_购物网站";
    }
  }
  return $title;
}
 
function gdh_get_title($title) {
  // var_dump(arg());
  $shopname_title = gdh_get_shopname_title();
  if ($shopname_title) {
      $title = $shopname_title;
  } else {
    $node_title = gdh_get_node_title();
    if ($node_title) {
      $title = $node_title;
    }
  }
  return $title;
}
drupal/script/title.txt · 最后更改: 2010/06/02 01:18 (外部编辑)