Joomla 1.5-获取类别和节函数-模板工具
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Joomla 1.5-获取类别和节函数-模板工具相关的知识,希望对你有一定的参考价值。
getCategory returns the category ID, getSection returns the section alias. Great for CSS overrides
function getCategory() { /** function for determining the category ID of a given page, referenced from: * http://forum.joomla.org/viewtopic.php?f=466&t=302292 */ $iId = JRequest::getVar('id',0); $database = &JFactory::getDBO(); if(JRequest::getVar( 'view', 0) == "section"){ return JRequest::getVar( 'id', 0); }else if(Jrequest::getVar( 'view', 0) == "category"){ $sql = "SELECT id FROM #__categories WHERE id = '$iId'"; $database->setQuery( $sql ); $row=$database->loadResult(); return $row; }else if(Jrequest::getVar('view', 0) == "article"){ $sql = "SELECT catid FROM #__content WHERE id = ".$temp[0]; $database->setQuery( $sql ); $row=$database->loadResult(); return $row; } } function getSection() { /** function for determining the section alias of a given page */ $menu = &JSite::getMenu(); if ($menu->getActive() == $menu->getDefault()){ return 'home'; } $iId = JRequest::getVar('id',0); $database = &JFactory::getDBO(); if(JRequest::getVar( 'view', 0) == "section"){ $sql = "SELECT alias " . "FROM #__sections WHERE id = ".$iId ; $database->setQuery( $sql ); $row=$database->loadResult(); return $row; }else if(Jrequest::getVar( 'view', 0) == "category"){ $sql = "SELECT a.alias " . "FROM #__sections as a, #__categories as b " . "WHERE (b.id = ".$iId ." " . "AND a.id = b.section)" ; $database->setQuery( $sql ); $row=$database->loadResult(); return $row; }else if(Jrequest::getVar('view', 0) == "article"){ //$sql = "SELECT sectionid FROM #__sections as a, #__content as b WHERE b.sectionid = a.id AND b.id = ".$temp[0]; $sql = "SELECT a.alias" . " FROM #__sections as a, #__content as b " . " WHERE (b.id = ".$temp[0] . " " . " AND a.id = b.sectionid)" ; $database->setQuery( $sql ); $row=$database->loadResult(); if (!$row) { return 'general'; // account for 'uncategorized' articles } return $row; }
以上是关于Joomla 1.5-获取类别和节函数-模板工具的主要内容,如果未能解决你的问题,请参考以下文章