2017-08-10 76 views
1

我想根據頁面的特定視圖將分類應用於div。如果頁面是一個類別博客視圖,我想添加類「博客視圖」,否則,如果頁面是一篇文章,我想應用類「articleview」。我會在我的模板的index.php文件中執行此操作。我怎麼能這樣做?如何檢測頁面是否是Joomla文章或分類博客視圖

在此先感謝。

回答

0

我已經解決了這個辦法:

<?php 
    if(JRequest::getVar('view') == 'article') 
    { 
     $articleviewornot = "articleview"; 
    } 
    if(JRequest::getVar('view') == 'category') 
    { 
     $categoryviewornot = "categoryview"; 
    } 
?> 
1

你可以有幾種方法處理這個問題,但我剛剛創建了$類變量並將其設置爲依據的觀點是你想要的類/佈局。

<?php 
$joomlaApp = JFactory::getApplication()->input; 
$option = $joomlaApp->getCmd('option'); 
$view = $joomlaApp->getCmd('view'); 
$layout = $joomlaApp->getCmd('layout'); 
$class = ''; 

if ($option == 'com_content' && $view == 'article'){ 
    $class = 'articleview'; 
}elseif($option == 'com_content' && $view == 'category' && $layout == 'blog'){ 
    $class = 'blogview'; 
} 
echo '<div class="'.$class.'">'; 
?> 
相關問題