2017-08-10 74 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.'">'; 
?> 
相关问题