旁门左道做joomla多级分类二

下面的工作是将分类列表页的排布成一级分类下面紧跟其所属二级分类,显示出父子关系,如:
一级分类一
____二级分类一
____二级分类二
一级分类二
____二级分类三
____二级分类四
。。。

还是关系到两个文件:
admin.categorise.html.php 显示文件
admin.categorise.php 查询文件
分别与function show( &$rows, $section, $section_name, &$page, &$lists, $type )
    和function showCategories( $section, $option )有关
1.admin.categorise.php的function showCategories( $section, $option )是原始文件中的查询,会把所有的一级、二级分类查询出来并显示,我们需要的是某一级分类下的二级分类都紧跟在该一级分类下,所以原始的查询不会做到。
我的处理方法是先把所有的一级分类查询出来,在输出某一级分类时调用新添加的方法,将该分类的子分类查出来并按一定格式输出,就可以了。
所以把admin.categorise.php的function showCategories( $section, $option )的查询语句添加一个限定条件‘ AND c.parent_id = 0’以便只查询一级分类。

2.编写新方法:仿照function showCategories( $section, $option )编写查询子分类方法
function showSubCat($parent_id, $section, $option){
		global $mainframe;
  	$db	=& JFactory::getDBO();
	$filter_order		= $mainframe->getUserStateFromRequest( $option.'.filter_order',					'filter_order',		'c.ordering',	'cmd' );
	$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir',				'filter_order_Dir',	'',				'word' );
	$filter_state		= $mainframe->getUserStateFromRequest( $option.'.'.$section.'.filter_state',	'filter_state',		'',				'word' );
	$sectionid			= $mainframe->getUserStateFromRequest( $option.'.'.$section.'.sectionid',		'sectionid',		0,				'int' );
	$search				= $mainframe->getUserStateFromRequest( $option.'.search',						'search',			'',				'string' );
	$search				= JString::strtolower( $search );
	$section_name 	= '';

	if ($filter_order == 'c.ordering'){
			$order 			= ' ORDER BY  z.title, c.ordering';
		} else {
			$order 			= ' ORDER BY  '.$filter_order.' '. $filter_order_Dir.', z.title, c.ordering';
		}
		
	if ( $sectionid > 0 ) {
		$filter = ' AND c.section = '.$db->Quote($sectionid);
	} else {
		$filter = '';
	}
	if ( $filter_state ) {
		if ( $filter_state == 'P' ) {
			$filter .= ' AND c.published = 1';
		} else if ($filter_state == 'U' ) {
			$filter .= ' AND c.published = 0';
		}
	}
	if ($search) {
		$filter .= ' AND LOWER(c.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
	}
	
  	$query = 'SELECT  c.*, c.checked_out as checked_out_contact_category, g.name AS groupname, u.name AS editor'
	. ' , z.title AS section_name'
	. ' FROM #__categories AS c'
	. ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
	. ' LEFT JOIN #__groups AS g ON g.id = c.access'
	. ' LEFT JOIN #__sections AS z ON z.id = c.section'
	. ' WHERE c.section NOT LIKE "%com_%"'
	. 'AND c.parent_id = '.$parent_id
	. $filter
	. ' AND c.published != -2'
	. ' GROUP BY c.id'
	. $order;
	$db->setQuery( $query );
	$rows = $db->loadObjectList();
	if ($db->getErrorNum()) {
		echo $db->stderr();
		return;
	}
	return $rows;
}


这样数据处理部分就结束了,剩下的就是显示的问题。

3.admin.categorise.html.php 的function show( &$rows, $section, $section_name, &$page, &$lists, $type )是显示分类列表的方法。对它进行改造。
找到循环输出条目的开始处:
		
for ($i=0, $n=count( $rows ); $i < $n; $i++) {
			$row 	= &$rows[$i];

下添加:
if(file_exists(dirname(__FILE__).DS.'admin.categories.php')){
			include_once(dirname(__FILE__).DS.'admin.categories.php');
			$row1 = showSubCat($row->id, $section, $option);
		}

将查询子分类的方法引入,并得到结果$row1
然后找到该一级分类输出结束处添加子分类的输出:
		foreach($row1 as $key=> $ro){
						JFilterOutput::objectHtmlSafe($ro);

			$ro->sect_link = JRoute::_( 'index.php?option=com_sections&task=edit&cid[]='. $ro->section );

			$link = 'index.php?option=com_categories&section='. $section .'&task=edit&cid[]='. $ro->id .'&type='.$type;

			$access 	= JHTML::_('grid.access',   $ro, $i );
			$checked 	= JHTML::_('grid.checkedout',   $ro, $i );
			$published 	= JHTML::_('grid.published', $ro, $i );
			?>
			<tr class="<?php echo "row$k"; ?>">
				<td>
					<?php echo $page->getRowOffset( $i ); ?>
				</td>
				<td>
					<?php echo $checked; ?>
				</td>
				<td>
					<span class="editlinktip hasTip" title="<?php echo JText::_( 'Title' );?>::<?php echo $ro->title; ?>">
					<?php
					if (  JTable::isCheckedOut($user->get ('id'), $ro->checked_out )  ) {
						if($ro->parent_id !=0) echo "——".$ro->title;
						else echo $ro->title;
					} else {
						?>
						<a href="<?php echo JRoute::_( $link ); ?>">
							<?php if($ro->parent_id !=0) echo "——".$ro->title; else echo $ro->title; ?></a>
						<?php
					}
					?></span>
				</td>
				<td align="center">
					<?php echo $published;?>
				</td>
				<td class="order">
					<span><?php echo $page->orderUpIcon( $i, ($ro->section == @$rows[$i-1]->section), 'orderup', 'Move Up', $ordering ); ?></span>
					<span><?php echo $page->orderDownIcon( $i, $n, ($ro->section == @$rows[$i+1]->section), 'orderdown', 'Move Down', $ordering ); ?></span>
					<?php $disabled = $ordering ?  '' : 'disabled="disabled"'; ?>
					<input type="text" name="order[]" size="5" value="<?php echo $ro->ordering; ?>" <?php echo $disabled ?> class="text_area" style="text-align: center" />
				</td>
				<td align="center">
					<?php echo $access;?>
				</td>
				<?php
				if ( $section == 'com_content' ) {
					?>
					<td>
						<a href="<?php echo $ro->sect_link; ?>" title="<?php echo JText::_( 'Edit Section' ); ?>">
							<?php echo $ro->section_name; ?></a>
					</td>
					<?php
				}
				?>
				<?php
				if ( $type == 'content') {
					?>
					<td align="center">
						<?php echo $ro->active; ?>
					</td>
					<td align="center">
						<?php echo $ro->trash; ?>
					</td>
					<?php
				}
				$k = 1 - $k;
				?>
				<td align="center">
					<?php echo $ro->id; ?>
				</td>
			</tr>
			<?php
		}

现在就可以显示了,如下图:


剩下的就是小问题了

你可能感兴趣的:(C++,c,PHP,C#,Access)