UCH日志增加系统分类技巧

实现用户日志系统分类,后台可管理编辑系统分类,支持二级分类。
首先,需要升级的SQL语句:

CREATE TABLE IF NOT EXISTS `uchome_blog_category` (
  `catid` mediumint(6) NOT NULL auto_increment,
  `catname` varchar(32) NOT NULL,
  `parentid` smallint(6) default NULL,
  `catorder` smallint(6) NOT NULL,
  PRIMARY KEY  (`catid`),
  KEY `parentid` (`parentid`),
  KEY `catname` (`catname`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;


ALTER TABLE `uchome_blog` ADD `catid` SMALLINT( 6 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `classid`;

其次,我们处理前台第一大部分:
1.1、打开space_blog.php文件:

//分类
if($classid) {
    $wheresql .= " AND b.classid='$classid'";
    $theurl .= "&classid=$classid";
}

下面加:

//系统分类
$catid = $_POST['catid']?$_POST['catid']:$_GET['catid'];
if(intval($catid)>0 ) {
    $wheresql.=" AND b.catid='$catid'";
    $theurl .= "&catid=$catid";
}

1.2、打开space_blog.php和cp_blog.php文件,在开头处加入以下代码:

//获得根分类及子分类
$sql = 'SELECT * FROM '.$_SC['tablepre'].'blog_category  order by catorder';
$query = $_SGLOBAL['db']->query( $sql );
while ($result=mysql_fetch_array($query,1)){
	if($result['parentid']==0){ //根分类
		$tmp_info['catid']=$result['catid'];
		$tmp_info['catname']=$result['catname'];
		$tmp_info['catorder']=$result['catorder'];
		$tmp_info['parentid']=$result['parentid'];
		$bloglist[]=$tmp_info;
	} else {
		//子分类
		$tmp_info_cat['catid']=$result['catid'];
		$tmp_info_cat['catname']=$result['catname'];
		$tmp_info_cat['catorder']=$result['catorder'];
		$tmp_info_cat['parentid']=$result['parentid'];
		$bloglist_cat[]=$tmp_info_cat;
	}
}
unset($sql);

1.3 打开function_blog.php文件,修改“$blogarr”部分如下:

	//主表
	$blogarr = array(
		'subject' => $POST['subject'],
		'classid' => $classid,
		'catid' => intval($POST['catid']), //系统分类
		'friend' => $POST['friend'],
		'password' => $POST['password'],
		'noreply' => empty($_POST['noreply'])?0:1
	);

1.4 打开cp_blog.htm文件,在“标签”上面加:


			
				个人分类
				
					
				
			
			
				系统分类
				
					
				
			

1.5 打开space_blog_list.php文件,在“个人分类”上面加:


    

系统分类

其次,我们处理第二大部分:后台数据的存与调。
2.1 新建admincp_blog_class.php文件:

$value){
		$data = array(
		 		"catorder" => $value
		  	);
		updatetable('blog_category',$data,'catid='.$key,0);	
	}
	cpmessage('更新成功!', 'admincp.php?ac=blog_class');
}

//获得根目录及子目录
$sql = 'SELECT * FROM '.$_SC['tablepre'].'blog_category  order by catorder';
$query = $_SGLOBAL['db']->query( $sql );
while ($result=mysql_fetch_array($query,1)){
	if($result['parentid']==0){
		$infolist[]=$result; //根目录
	}else{
		$infolist_cat[]=$result; //子目录
	}
}
$op=$_GET['op'];
switch ($addinfo){
	case 'add': 
		 if(isset($_POST['infosubmit'])){
		 	$data = array(
		 		"catname" => $_POST['catname'],
		 		"catorder" => $_POST['catorder'],
		 		"parentid" =>$_POST['parentid']
		  	);
			inserttable( "blog_category", $data, 1 );
			cpmessage('添加新分类成功!', 'admincp.php?ac=blog_class');
	 	}
	break;
	case 'edit':
		if(!isset($_POST['infosubmit'])){//如果没返回则说明进入修改界面
			$sql = 'SELECT * FROM '.$_SC['tablepre'].'blog_category where catid='.$_GET['catid'];
			$query = $_SGLOBAL['db']->query( $sql );
			$result=mysql_fetch_array($query,1);
			$infovalue['catid']=$_GET['catid'];
			$infovalue['catname']=$result['catname'];
			$infovalue['catorder']=$result['catorder'];
			$infovalue['parentid']=$result['parentid'];
		}else //如果返回则修改数据库内容
		{
			if($_POST['parentid']==$_POST['catid']){
				cpmessage('不能将自己设为自己的上级菜单!', 'admincp.php?ac=blog_class&op=edit&catid='.$_POST['catid']);	
				exit;
			}
			$data = array(
		 		"catname" => $_POST['catname'],
		 		"catorder" => $_POST['catorder'],
		 		"parentid" =>$_POST['parentid']
		  	);
		  	updatetable('blog_category',$data,'catid='.$_POST['catid'],0);
		  	cpmessage('修改成功!', 'admincp.php?ac=blog_class');
		}
	break;
	case 'delete':
		$sql='delete FROM '.$_SC['tablepre'].'blog_category where catid='.$_GET['catid'];
		$query = $_SGLOBAL['db']->query( $sql );
		cpmessage('删除成功!', 'admincp.php?ac=blog_class');
	break;
	default:
}
?>

2.2 新建tpl/blog_class.htm文件:



$thevalue
分类名称 显示顺序 操作
$value[catname] 编辑 | 删除
    |—— $value_cat[catname]          编辑 | 删除
分类名称:
上级分类:
显示顺序

最后一步,修改admincp.php文件,
查找:

 'blog',

下面加:

 'blog_class',

相关文章:

1、提高PHP编程效率的53个要点
https://www.onexin.net/labs/php-programming-to-improve-the-efficiency-of-the-53-points/

2、26个有用的jQuery的提示,技巧及解决方案
https://www.onexin.net/latest/26-jquery-useful-tips-techniques-and-solutions/

3、让PHP开发者事半功倍的十大技巧
https://www.onexin.net/languages/allow-php-developers-multiplier-ten-tips/

4、UCH远程图片本地化添加水印
https://www.onexin.net/discuz/ucenter_home/localization-of-uch-remote-image-watermark/

5、PHP字符串处理的十个技巧
https://www.onexin.net/languages/php-string-handling-of-the-10-methods/

转载请注明出处:https://www.onexin.net/discuz/ucenter_home/increase-in-uch-log-taxonomy-coup/

Leave a Reply

Your email address will not be published. Required fields are marked *