Joomla 1.5-获取类别和节函数-模板工具

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Joomla 1.5-获取类别和节函数-模板工具相关的知识,希望对你有一定的参考价值。

getCategory returns the category ID, getSection returns the section alias. Great for CSS overrides
  1. function getCategory() {
  2. /** function for determining the category ID of a given page, referenced from:
  3. * http://forum.joomla.org/viewtopic.php?f=466&t=302292
  4. */
  5. $iId = JRequest::getVar('id',0);
  6. $database = &JFactory::getDBO();
  7. if(JRequest::getVar( 'view', 0) == "section"){
  8. return JRequest::getVar( 'id', 0);
  9. }else if(Jrequest::getVar( 'view', 0) == "category"){
  10. $sql = "SELECT id FROM #__categories WHERE id = '$iId'";
  11. $database->setQuery( $sql );
  12. $row=$database->loadResult();
  13. return $row;
  14. }else if(Jrequest::getVar('view', 0) == "article"){
  15. $temp = explode(":",JRequest::getVar('id',0));
  16. $sql = "SELECT catid FROM #__content WHERE id = ".$temp[0];
  17. $database->setQuery( $sql );
  18. $row=$database->loadResult();
  19. return $row;
  20. }
  21. }
  22.  
  23. function getSection() {
  24. /**
  25. function for determining the section alias of a given page
  26. */
  27. $menu = &JSite::getMenu();
  28. if ($menu->getActive() == $menu->getDefault()){
  29. return 'home';
  30. }
  31. $iId = JRequest::getVar('id',0);
  32. $database = &JFactory::getDBO();
  33. if(JRequest::getVar( 'view', 0) == "section"){
  34. $sql = "SELECT alias "
  35. . "FROM #__sections WHERE id = ".$iId
  36. ;
  37. $database->setQuery( $sql );
  38. $row=$database->loadResult();
  39. return $row;
  40. }else if(Jrequest::getVar( 'view', 0) == "category"){
  41. $sql = "SELECT a.alias "
  42. . "FROM #__sections as a, #__categories as b "
  43. . "WHERE (b.id = ".$iId ." "
  44. . "AND a.id = b.section)"
  45. ;
  46. $database->setQuery( $sql );
  47. $row=$database->loadResult();
  48. return $row;
  49. }else if(Jrequest::getVar('view', 0) == "article"){
  50. $temp = explode(":",JRequest::getVar('id',0));
  51. //$sql = "SELECT sectionid FROM #__sections as a, #__content as b WHERE b.sectionid = a.id AND b.id = ".$temp[0];
  52. $sql = "SELECT a.alias"
  53. . " FROM #__sections as a, #__content as b "
  54. . " WHERE (b.id = ".$temp[0] . " "
  55. . " AND a.id = b.sectionid)"
  56. ;
  57. $database->setQuery( $sql );
  58. $row=$database->loadResult();
  59. if (!$row)
  60. {
  61. return 'general'; // account for 'uncategorized' articles
  62. }
  63. return $row;
  64. }

以上是关于Joomla 1.5-获取类别和节函数-模板工具的主要内容,如果未能解决你的问题,请参考以下文章

显示修改日期类别列表 joomla 1.5

joomla 1.5 搜索与自定义组件的集成?

Joomla 1.5模板XML

如何为 k2 类别创建自定义模板并将此模板分配给 Joomla 支持?

Joomla 1.5 在主页上启用新闻

在 Joomla 替代布局和使用 K2 模板之间感到困惑