ITeye博客

旁门左道做joomla多级分类一

aiou · 2009-07-16 16:28 · joomla · 编程语言 · HTML · C · C++ · PHP · C# · Markdown

利用parent_id,暂时只考虑增加一级分类,而不是无限分类 单元->一级分类->二级分类->文章 1. admin.categories.php的function editCategory($edit )里仿照section代码添加: [code="php"]$category = JRequest::getCmd( 'category', 'com_content' );[/code] 和 [code="php"] // build the html select list for Categories if ( $category == 'com_content' ) { if (!$row->catid && JRequest::getInt('parent_id')) { $row->catid = JRequest::getInt('parent_id'); } $query = 'SELECT c.id AS value, c.title AS text' . ' FROM #__categories AS c' . ' WHERE c.section NOT LIKE "%com_%"' . ' AND c.published != -2' . ' ORDER BY c.ordering' ; $db->setQuery( $query ); $category = $db->loadObjectList(); $lists['category'] = JHTML::_('select.genericlist', $category, 'parent_id', 'class="inputbox" size="1"', 'value', 'text', $row->cateid ); } 至此可以显示选择parent_id表单并可以保存parent_id值, 以上不用了 换为以下代码: foreach ($sections as $section) { $section_list[] = (int) $section->value; // get the type name - which is a special category if ($row->section) { if ($section->id == $row->section) { $contentSection = $section->text; } } else { if ($section->id == $row->section) { $contentSection = $section->text; } } } $sectioncategories = array (); $sectioncategories[-1] = array (); $sectioncategories[-1][] = JHTML::_('select.option', '-1', JText::_( 'Select Category' ), 'id', 'title'); $section_list = implode('\', \'', $section_list); $query = 'SELECT id, title, section' . ' FROM #__categories' . ' WHERE section IN ( \''.$section_list.'\' )' . ' AND parent_id = 0 ' . ' ORDER BY ordering'; $db->setQuery($query); $cat_list = $db->loadObjectList(); // Uncategorized category mapped to uncategorized section $uncat = new stdClass(); $uncat->id = 0; $uncat->title = JText::_('Uncategorized'); $uncat->section = 0; $cat_list[] = $uncat; foreach ($sections as $section) { $sectioncategories[$section->value] = array (); $rows2 = array (); foreach ($cat_list as $cat) { if ($cat->section == $section->value) { $rows2[] = $cat; } } foreach ($rows2 as $row2) { $sectioncategories[$section->value][] = JHTML::_('select.option', $row2->id, $row2->title, 'id', 'title'); } } $categories = array(); foreach ($cat_list as $cat) { if($cat->section == $row->section) $categories[] = $cat; } $categories[] = JHTML::_('select.option', '0', JText::_( 'Select Category' ), 'id', 'title'); $lists['parent_id'] = JHTML::_('select.genericlist', $categories, 'parent_id', 'class="inputbox" size="1"', 'id', 'title', $row->parent_id);[/code] 方法最下面修改代码为; categories_html::edit( $row, $lists, $redirect,$sectioncategories ); 将$sectioncategories的值也传入到categories_html::edit()方法里。 添加js:用于动态更换分类列表,当改变单元时,分类随之改变。 2. admin.categories.html.php的function edit( &$row, &$lists, $redirect )里添加: [code="php"] : [/code] 显示父分类选项表单 添加js代码,把$sectioncategories值传给js程序。用于动态改变分类列表选项 [code="html"]

评论(2)

  1. #2 楼 · aiou · 2011-09-08 09:52

    mymoola writes:

    请问能不能在整理一下,看到写着有些代码不要了什么的 ,有点晕乎了, 现在1.5还是大流,请问能不能再重新整理一下这个 第一篇。

    就是第三点不需要了

  2. #1 楼 · mymoola · 2011-08-12 18:56

    请问能不能在整理一下,看到写着有些代码不要了什么的 ,有点晕乎了, 现在1.5还是大流,请问能不能再重新整理一下这个 第一篇。

评论功能维护中,当前仅展示历史评论。