2012-10-11 21 views
0

我是新來的Drupal 7元標記添加到特定頁面僅

我有不同的基本的頁面,我使用meta標記要遍歷每個頁面:

<meta http-equiv="refresh" content="20; url=http://sitename/node/page2" /> 

第2頁將有meta標記

<meta http-equiv="refresh" content="10; url=http://sitename/node/page3" /> 

我該怎麼做?我希望元標記僅添加在基本頁面上

我試着使用TEMPLATEUSED_preprocess_html添加元標記,但是我已經意識到這是錯誤的,因爲它不是動態的並且適用於每個頁面。

回答

1

drupal_add_html_head有助於向頭部添加標籤,請檢查下面的示例。

// First, we must set up an array 
$element = array(
    '#tag' => 'link', // The #tag is the html tag - <link /> 
    '#attributes' => array(// Set up an array of attributes inside the tag 
    'href' => 'http://fonts.googleapis.com/css?family=Cardo&subset=latin', 
    'rel' => 'stylesheet', 
    'type' => 'text/css', 
), 
); 
drupal_add_html_head($element, 'google_font_cardo'); 

這將輸出以下HTML:

<link href="http://fonts.googleapis.com/css?family=Cardo&amp;subset=latin" rel="stylesheet" type="text/css" /> 
1

這是一個老問題,但它仍然沒有更具體的迴應。看起來我們必須使用preprocess_html在template.php中添加一個head元素。 $ node不可用(至少我無法從template.php/preprocess_html中訪問它),但我可以使用drupal_get_path_alias獲取路徑,這就是原始問題的要求。

這是我的工作例如:

function THEMENAME_preprocess_html(&$variables) { 
    if (drupal_get_path_alias() == "node/45") { 
    $meta_refresh = array(
     '#type' => 'html_tag', 
     '#tag' => 'meta', 
     '#attributes' => array( 
     'http-equiv' => 'refresh', 
     'content' => '900, url=/node/45', 
    ), 
    ); 
    drupal_add_html_head($meta_refresh, 'meta_refresh'); 
    } 
} 

使用CASE語句,可以更好地服務於沃倫的兩條路徑。

相關問題