我正在使用帶有用於drupal的圖像庫的imagecache。當該字段設置爲鏈接到原始圖像的圖像緩存預設時。我希望它能夠在點擊預設圖像時將原始圖像加載到新選項卡中。如何將target =「_ blank」屬性添加到圖像緩存預設?Drupal - imagecache鏈接到圖像,將屬性設置爲目標=「_ blank」
回答
您需要覆蓋鏈接到您的主題中的圖像字段格式化程序的圖像,該圖像由theme_imagecache_formatter_imagelink()
創建。添加到您的主題的template.php
:
function mytheme_imagecache_formatter_mypreset_imagelink($element) {
// Inside a view $element may contain NULL data. In that case, just return.
if (empty($element['#item']['fid'])) {
return '';
}
// Extract the preset name from the formatter name.
$presetname = substr($element['#formatter'], 0, strrpos($element['#formatter'], '_'));
$style = 'imagelink';
$item = $element['#item'];
$item['data']['alt'] = isset($item['data']['alt']) ? $item['data']['alt'] : '';
$item['data']['title'] = isset($item['data']['title']) ? $item['data']['title'] : NULL;
$imagetag = theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title']);
$path = file_create_url($item['filepath']);
$class = "imagecache imagecache-$presetname imagecache-$style imagecache-{$element['#formatter']}";
return l($imagetag, $path, array('attributes' => array('class' => $class, 'target' => '_blank'), 'html' => TRUE));
}
分別替換mytheme
和mypreset
與主題的短名稱和您預設的簡稱。該功能與theme_imagecache_formatter_imagelink()
相同,除了最後一行,它將target="_blank"
屬性添加到鏈接。
甜!我是否必須爲每個預設定義一個新功能,或者是否有將它們組合的方法? – Toxid 2010-08-14 01:47:04
截至目前,您必須爲每個預設定義一個新功能。應該可以直接用'mytheme_imagecache_formatter_imagelink()'重寫'theme_imagecache_formatter_imagelink()',但是Imagecache使用的是深度魔法,我不完全理解需要主題函數名稱擴展。當我知道這是爲什麼時,會更新我的答案。 – 2010-08-14 03:49:26
- 1. 添加鏈接到圖像和目標=「_ blank」
- 2. 添加目標=「_ blank」以鏈接到JavaScript
- 3. 將背景圖像設置爲鏈接?
- 4. 用imagecache(Drupal)查看全尺寸鏈接
- 5. PHP鏈接問題與目標=「_ blank」
- 6. 使用Drupal ImageCache調整圖像質量
- 7. Drupal的ImageCache模塊不顯示圖像
- 8. 設置爲鏈接的屬性在NIAttributedLabel
- 9. 使用拼接將圖像url設置爲背景屬性
- 10. Drupal ImageCache動作特性?
- 11. 將圖像源設置爲從鏈接檢索到的值href
- 12. Drupal圖像作爲圖像鏈接到節點
- 13. 設置PikaChoose圖像爲超鏈接
- 14. JavaScript可以根據圖像的ID設置鏈接和標題等屬性嗎?
- 15. 將圖像標題屬性設爲標題樣式?
- 16. 如何將動作屬性動態設置爲超鏈接?
- 17. 如何將圖像鏈接到標題
- 18. 將標題鏈接到drupal中的URL
- 19. 將ObjectDataProvider設置爲視圖的屬性
- 20. 將目標鏈接到庫
- 21. 我想從圖像標題屬性並將其添加到周圍的鏈接
- 22. 如何將圖像的標題屬性鏈接到彈出窗口div
- 23. AutoMapper將目標上的所有屬性設置爲NULL
- 24. 將CSS屬性選擇器設置爲:目標
- 25. AutoMapper設置屬性設置爲null目標對象
- 26. iOS 5 MainStoryBoard:將視圖鏈接爲PUSH時,我們可以設置屬性嗎?
- 27. 將目標=「_ blank」添加到iframe中的鏈接而不使用<body onload>
- 28. Drupal Imagecache不工作
- 29. drupal cck image_field和imagecache
- 30. 將屬性設置爲com.google.appengine.api.datastore.Entity
對於您的信息:嚴格的文檔類型不支持目標屬性。你可以寫: onclick =「window.open(this.href); return false;」 – Rimian 2010-08-14 06:18:52