[英]How to detect if the page is a Joomla article or category blog view
I would like to apply a class to a div according to a specific view of the page. 我想根据页面的特定视图将类应用于div。 If the page is a category blog view I want to add the class "blogview" else if the page is an article I want to apply the class "articleview".
如果该页面是类别博客视图,我想添加类“blogview”,如果该页面是一篇文章我想要应用“articleview”类。 I would do this in the index.php file of my template.
我会在我的模板的index.php文件中执行此操作。 How could I do that?
我怎么能这样做?
Thanks in advance. 提前致谢。
JRequest
is deprecated. JRequest
已弃用。 Use JFactory::getApplication()->input
instead. 请改用
JFactory::getApplication()->input
。 For example JFactory::getApplication()->input->get('view')
例如
JFactory::getApplication()->input->get('view')
See: https://docs.joomla.org/Retrieving_request_data_using_JInput 请参阅: https : //docs.joomla.org/Retrieving_request_data_using_JInput
You could handle this in a few ways but I've just created a $class variable and set it to the classes that you want based on the view / layout. 您可以通过几种方式处理此问题,但我刚刚创建了一个$ class变量,并根据视图/布局将其设置为您想要的类。
<?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.'">';
?>
I've solved this way: 我这样解决了:
<?php
if( JRequest::getVar( 'view' ) == 'article' )
{
$articleviewornot = "articleview";
}
if( JRequest::getVar( 'view' ) == 'category' )
{
$categoryviewornot = "categoryview";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.