أحتاج إلى إضافة علامة وصفية مخصصة إلى موقع D7 ، مثل هنا: http://groups.drupal.org/node/83069 . ما هي الخيارات الممكنة؟ أعلم أن هناك وحدة metatag ، ولكن يبدو أنها لا تدعم العلامات المخصصة.
يمكنني تعديل السمة ، لكني بحاجة إلى حل قابل للتكوين من قبل المستخدم.
هل ألقيت نظرة على العلامات الوصفية سريعة ؟
Metatag يدعم العلامات المخصصة من خلال تنفيذ hook_metatag_metatags_view_alter () . شاهد تنفيذ الخطاف التالي لإضافة الرسم البياني المفتوح video: Duration علامة وصفية من كيان مخصص:
/**
* Alter metatags before being cached.
*
* This hook is invoked prior to the meta tags for a given page are cached.
*
* @param array $output
* All of the meta tags to be output for this page in their raw format. This
* is a heavily nested array.
* @param string $instance
* An identifier for the current page's page type, typically a combination
* of the entity name and bundle name, e.g. "node:story".
*/
function mycustommodule_metatag_metatags_view_alter(&$output, $instance) {
if ($instance == 'mycustom:entity') {
$entity = mycustomentity_load(someid);
$duration = $entity->duration;
$output['video:duration']['#attached']['drupal_add_html_head'][0] = array(
array(
'#theme' => 'metatag_opengraph',
'#tag' => 'meta',
'#id' => 'video:duration',
'#name' => 'video:duration',
'#value' => $duration,
),
'video:duration',
);
}
}
الرد في وقت متأخر ولكن هذا قد يكون مفيدًا للآخرين:
لقد كتبت عن حل بلدي هنا http://mymixerone.blogspot.in/2012/11/adding-meta-tags-in-drupal-node.html
مجرد إلقاء نظرة إذا كان ذلك مفيدا.
فيما يلي الحل باختصار ، حاول إضافة هذا في ملف templet.php الخاص بك:
<?php
function <theme-name>_preprocess_html(&$variables) {
switch(arg(1)) {
//current-issues, node id 33
case "33" :
// title
$variables['head_title']= "New Title";
//key-words
$page_keywords = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'keywords',
'content' => 'all keywords for this node',
)
);
drupal_add_html_head($page_keywords, 'page_keywords');
break;
//node id 20
case "20" :
// title
$variables['head_title']= "New Title";
break;
}
}
?>
يمكن إضافة علامات أخرى بالمثل.
شكرا أتول. لقد استخدمت نهجك لجعل الصفحة منعشة في Drupal كل 30 ثانية.
function garland_preprocess_html(&$vars) {
//Adding Refresh to main tikets page BEGIN
//print 'Node id = ';print(arg(1));
switch(arg(1)){
//check node id : if nid=kontora then use custom "Refresh setup" (must be the name of client you want to refresh)
case "client1" :
/*Implementation of HTML equivalent <meta http-equiv="Refresh" content="30" />*/
$http_equiv = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'Refresh',
'content' => '30',
)
);
drupal_add_html_head($http_equiv, 'http_equiv');
// Meta tag code here
break;
/*
//node id 20
case "20" :
// Meta tag code here
break;*/
}
//Adding Refresh to main tikets page END
}
يمكنك أيضًا تنفيذ hook_metatag_info في وحدة نمطية مخصصة ، وتحديد علامة تعريفك ثم يمكنك تهيئتها باستخدام واجهة المستخدم.
يمكنك مشاهدة هذا التنفيذ من وحدة metatag ، على سبيل المثال http://www.drupalcontrib.org/api/drupal/contributions٪21metatag٪21metatag_opengraph٪21metatag_opengraph.metatag.inc/function/metatag_opengraph_metatag_info/7