[英]Only show a view on a certain content type in Drupal
我在Drupal中構建了一個“關於作者”視圖塊。 這是在當前節點的創建者的user_id處鏈接的,這非常有效。
但是,我現在想知道如何將視圖限制為某些內容類型。 我不希望它只在博客上展示故事。 我嘗試用Arguments做到這一點,但到目前為止我還沒有運氣。
誰能幫我嗎?
我建議使用pathauto為該類型的每個節點提供一個公共URL前綴(無論如何都是個好主意),因此您可以使用簡單的塊可見性路徑限制。 例如,您將內容類型路徑模式設置為“article / [title]”,然后將塊路徑設置為“article / *”
不,您可以使用view的內置參數驗證器。
恩。 如何將視圖限制為用戶的uid值?“意思是,只有擁有該內容的登錄用戶才能看到任何給定視圖。
這是Views Argument PHP Validator代碼。
global $user; return $argument[0] == $user->uid;
只需創建視圖,轉到塊配置頁面並使用php獲取塊可見性規則。 要僅在某些內容類型上顯示該塊,請使用:
<?php
$match = FALSE;
$types = array('story' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}
return $match;
?>
此代碼取自drupal.org, 概述方法以阻止可見性
更好:
<?php
$match = FALSE;
$types = array('story' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load($nid);
$type = $node->type;
if (isset($types[$type])) {
$match = TRUE;
}
}
return $match;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.