调用方法如下:
复制代码代码如下:
$Template= '<li class="xxx">[<a href="{catedir}">{catetitle}</a>]<a href="{html}" />
类代码如下:
复制代码代码如下:
<?php
/**
* 文章类,方便文章列表、内容的调用
* 仅支持PHP5
*
* 类函数列表:
* getArticleListByCateId();
*
* @author Zerolone
* @version 2011-3-14 9:53:42
*
* 2011-1-31 10:11:07 增加静态方法 getCatePreviewUrl getPreviewUrl
*/
class Article {
public $CateId = 0; //栏目编号 0,可以为一个栏目编号, 或者多个栏目。例如:12, 或者12,13
public $Count = 10; //记录数 10
public $TitleCount = 20; //文字显示数 20
public $BeginCount = 0; //起始记录数 0
public $OrderBy = 'id'; //排序字段 默认以id字段排序
public $OrderSort = 'DESC'; //排序顺序 默认DESC,倒序
public $OrderBy2 = ''; //排序字段2
public $OrderSort2 = ''; //排序顺序2
public $Area = 0; //显示区域 0,全部显示
public $Flag = ISSUEFLAG; //显示文章状态 2,2为 已保存 已发布
public $Pic = 0; //仅调用有图片的 0,1为仅调用有图的
public $Video = 0; //仅调用有视频的 0,1为仅调用视频的
public $notshowlist= 0; //不显示不在列表中的 0,不显示, 1 显示
public $AndWhere = ''; //额外加入的查询
public $Loop = 0; //循环列表 0,
public $Template = ''; //模板
public $IdList = ''; //Id列表,用于外部调用
//内部使用的变量
protected $SqlCateId = ''; //栏目Sql语句
protected $SqlCateTitleId = ''; //栏目Sql语句
protected $SqlArea = ''; //显示区域Sql语句
protected $SqlFlag = ''; //状态
protected $SqlNotShow = ''; //不显示列表中
protected $SqlPic = ''; //是否仅调用图片
protected $SqlVideo = ''; //是否仅调用视频
protected $SqlOrder = ''; //排序
protected $SqlLimit = ''; //显示个数
protected $SqlWhere = ''; //加入查询
public $SqlStr = ''; //调试用
/**
* 初始化Sql语句
*
*/
function InitSql(){
//栏目编号
$CateId=$this->CateId;
if (strpos($CateId, ',')) {
$this->SqlCateId=' AND `cateid` in ('.$CateId.')';
} elseif ($CateId>0) {
$this->SqlCateId=' AND `cateid` ='.$CateId;
}
if ($CateId==0) $this->SqlCateId='';
/*
$CateId=$this->CateId;
$this->SqlCateTitleId=' AND `id` ='.$CateId;
*/
//显示区域
$Area=$this->Area;
if ($Area>0) {
$Area+=0;
$this->SqlArea= ' AND `area'.$Area.'` =1';
}
//状态
$this->SqlFlag= ' AND `flag` = '. $this->Flag;
//列表中不显示
$this->SqlNotShow= ' AND `notshowlist` = '. $this->notshowlist;
//图片
$Pic = $this->Pic;
if ($Pic==1){
$this->SqlPic= ' AND (`pic1` <>"" or `pic2`<>"") ';
}else {
$this->SqlPic= '';
}
//视频
$Video = $this->Video;
if ($Video==1){
$this->SqlVideo= ' AND `isvideo`=1 ';
}else {
$this->SqlVideo= '';
}
//额外加入的查询
$AndWhere = $this->AndWhere;
if ($AndWhere<>''){
$this->SqlWhere = ' And ' . $AndWhere;
}
//排序
$this->SqlOrder= ' ORDER BY `'.$this->OrderBy.'` '.$this->OrderSort;
if ($this->OrderBy2!='') $this->SqlOrder.= ' ,`'.$this->OrderBy2.'` '.$this->OrderSort2;
//显示个数
$this->SqlLimit= ' LIMIT '.$this->BeginCount.', '.$this->Count.';';
}
/**
* 清除,置为默认
*/
function Clear(){
$this->CateId = 0; //栏目编号 0,可以为一个栏目编号, 或者多个栏目。例如:12, 或者12,13
$this->Count = 10; //记录数 10
$this->TitleCount = 20; //文字显示数 20
$this->BeginCount = 0; //起始记录数 0
$this->OrderBy = 'id'; //排序字段 默认以id字段排序
$this->OrderSort = 'DESC'; //排序顺序 默认DESC,倒序
$this->Area = 0; //显示区域 0,全部显示
$this->Flag = ISSUEFLAG; //显示文章状态 2,2为 已保存 已发布
$this->Pic = 0; //仅调用有图片的 0,1为仅调用有图的
$this->Video = 0; //仅调用有视频的 0,1为仅调用视频的
$this->notshowlist = 0; //不显示不在列表中的 0,不显示, 1 显示
$this->AndWhere = ''; //额外加入的查询
$this->Loop = 0; //循环列表 0,
$this->Template = ''; //模板
}
/**
* 返回文章内容字符串
*
* {<li class="xxx"><a href="{html}" />
数据库
复制代码代码如下:
--
-- 表的结构 `mc_article`
--
CREATE TABLE IF NOT EXISTS `mc_article` (
`id` int(10) unsigned NOT NULL auto_increment COMMENT '编号',
`comment` tinyint(3) unsigned NOT NULL COMMENT '是否留言',
`comments` tinyint(3) unsigned NOT NULL COMMENT '留言条数',
`commentcheck` tinyint(3) unsigned NOT NULL COMMENT '回复审核',
`posttime` int(10) unsigned NOT NULL COMMENT '提交时间',
`title` varchar(255) NOT NULL COMMENT 'Title',
`title2` varchar(255) default NULL COMMENT 'Title2',
`content` text COMMENT 'Content',
`flag` tinyint(1) NOT NULL default '0' COMMENT '标志',
`cateid` int(10) unsigned NOT NULL default '0' COMMENT '栏目编号',
`sourceid` mediumint(8) unsigned NOT NULL default '0',
`reurl` varchar(255) default NULL COMMENT '跳转地址',
`hits` mediumint(8) unsigned NOT NULL default '0' COMMENT '点击数',
`author` varchar(255) default NULL COMMENT '作者',
`from` varchar(255) default NULL COMMENT '来源',
`keyword` varchar(255) default NULL COMMENT '关键字',
`order` tinyint(4) unsigned NOT NULL default '99' COMMENT '顺序',
`memo` text COMMENT '简介',
`pic1` varchar(255) default NULL COMMENT '图片一',
`pic2` varchar(255) default NULL COMMENT '图片二',
`userid` int(10) unsigned NOT NULL default '0' COMMENT '用户编号',
`html` varchar(255) default NULL COMMENT '地址',
`ishtml` tinyint(3) unsigned NOT NULL default '0' COMMENT '是否生成',
`area` int(10) unsigned NOT NULL default '0' COMMENT '显示区域',
`custom1` varchar(255) default NULL COMMENT '自定义1',
`custom2` varchar(255) default NULL COMMENT '自定义2',
`custom3` varchar(255) default NULL COMMENT '自定义3',
`custom4` varchar(255) default NULL COMMENT '自定义4',
`custom5` varchar(255) default NULL COMMENT '自定义5',
`res_id` int(10) unsigned NOT NULL default '0',
`special` varchar(255) default NULL,
`area1` tinyint(1) unsigned NOT NULL default '0',
`area2` tinyint(1) unsigned NOT NULL default '0',
`area3` tinyint(1) unsigned NOT NULL default '0',
`area4` tinyint(1) unsigned NOT NULL default '0',
`area5` tinyint(1) unsigned NOT NULL default '0',
`isvideo` tinyint(1) unsigned NOT NULL default '0' COMMENT '是否视频节目',
`notshowlist` tinyint(4) NOT NULL default '0' COMMENT '不显示在列表',
`titlecolor` varchar(7) default NULL COMMENT '标题颜色',
`url` varchar(255) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Article' AUTO_INCREMENT=87 ;
--
-- 转存表中的数据 `mc_article`
--
INSERT INTO `mc_article` (`id`, `comment`, `comments`, `commentcheck`, `posttime`, `title`, `title2`, `content`, `flag`, `cateid`, `sourceid`, `reurl`, `hits`, `author`, `from`, `keyword`, `order`, `memo`, `pic1`, `pic2`, `userid`, `html`, `ishtml`, `area`, `custom1`, `custom2`, `custom3`, `custom4`, `custom5`, `res_id`, `special`, `area1`, `area2`, `area3`, `area4`, `area5`, `isvideo`, `notshowlist`, `titlecolor`, `url`) VALUES
(1, 0, 0, 0, 0, '学堂介绍', '', '<DL>\r\n<DD> </DD>\r\n<DT><FONT style="BACKGROUND-COLOR: #0000ff" color=#800000>【测试修改】</FONT>重庆漫想族文化<FONT color=#ff0000>传播有限公司是一家集合原创</FONT>动画、娱乐产品开发,提供多媒体制作并以电视、网络传播为平台的现代化动漫文化开发推广策划制作公司。于2008年4月入驻重庆高新开发区北部新区重庆动漫基地。<BR>漫想族公司通过自己多<STRONG>年的管理运作,建立了西南地区最</STRONG>大的无纸动画生产基地,集合了业界内最优秀的精英的团队。并与国内多家影视机构、出版社、数字艺术厂商、多媒体平台建立了良好的合作关系,实现优势互补、资源共享,在业界和市场上都形成了广泛和深远的影响力。<BR>目前公司主要从事原创电视动画、原创电影动画等品牌产品的开发,同时还涉及光盘出版、图书制作发行、广告制作、游戏开发以及文化产品授权等业务领域。漫想族公司一直坚定信奉精品至上路线,努力为社会奉献精品,努力开拓中国动漫市场。漫想族公司一直坚定信奉精品至上路线,努力为社会奉献精品,努力开拓中国动漫市场。漫想族公司一直坚定信奉精品至上路线,努力为社会奉献精品,努力开拓中国动漫市场。</DT>\r\n<P class=clrB></P></DL>', 0, 28, 0, '', 2, '', '', '', 255, '', '', '', 1, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, '', NULL),
(2, 0, 0, 0, 0, '公司简介', '', '公司简介公司简介公司简介公司简介公司简介公司简介公司简介公司简介公司简介公司简介', 1, 28, 0, '', 0, '', '', '', 255, '', '', '', 1, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, '', NULL),
(3, 0, 0, 0, 0, '最新动态', '', '<P><IMG />
分类结构
复制代码代码如下:
-- --------------------------------------------------------
--
-- 表的结构 `mc_article_cate`
--
CREATE TABLE IF NOT EXISTS `mc_article_cate` (
`id` int(10) unsigned NOT NULL auto_increment,
`parentid` int(10) default NULL,
`level` char(50) default NULL,
`title` char(100) default NULL,
`templateid` int(10) default NULL,
`forumid` int(10) default NULL,
`catetemplateid` int(10) default NULL,
`dir` char(100) default NULL,
`kind` tinyint(4) default '0' COMMENT '显示方式',
`pagesize` tinyint(4) default '0' COMMENT '显示条数',
`specialid` int(10) default '0' COMMENT '对应专题编号',
`url` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='cate' AUTO_INCREMENT=40 ;
--
-- 转存表中的数据 `mc_article_cate`
--
INSERT INTO `mc_article_cate` (`id`, `parentid`, `level`, `title`, `templateid`, `forumid`, `catetemplateid`, `dir`, `kind`, `pagesize`, `specialid`, `url`) VALUES
(1, 0, '01', '测试大类', 9, NULL, 9, '/test/', 0, 0, 0, ''),
(3, 0, '03', '楼盘调用', NULL, NULL, NULL, 'getbuild', 0, 0, 0, ''),
(4, 0, '04', '学习环境', NULL, NULL, NULL, '/asdf/', 0, 0, 0, ''),
(5, 0, '05', '报名方式', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(6, 0, '06', '学员作品', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(7, 0, '07', '校院合作', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(38, 0, '17', '购房宝典', 2, NULL, 2, 'baodian', 0, 0, 0, ''),
(25, 6, '0601', '插画学员作品', NULL, NULL, NULL, NULL, 0, 0, 0, 'works.php'),
(26, 6, '0602', '动画学员作品', NULL, NULL, NULL, NULL, 0, 0, 0, 'works.php'),
(28, 0, '08', '调用文章', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(29, 3, '0301', '新上市', NULL, NULL, NULL, 'getbuild/new', 0, 0, 0, ''),
(30, 3, '0302', '本月开盘', NULL, NULL, NULL, 'getbuild/this', 0, 0, 0, ''),
(31, 3, '0303', '下月开盘', NULL, NULL, NULL, 'getbuild/next', 0, 0, 0, ''),
(32, 25, '060101', '第一期', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(33, 25, '060102', '第二期', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(34, 25, '060103', '第三期', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(35, 25, '060104', '第四期', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(36, 26, '060201', '第一期', NULL, NULL, NULL, NULL, 0, 0, 0, ''),
(39, 1, '0101', 'sf', 9, NULL, 2, '/test/sub/', 0, 0, 0, '');
视图代码:
复制代码代码如下:
-- 视图结构 `mc_view_article`
CREATE VIEW `mc_view_article` AS select `mc_article`.`id` AS `id`,`mc_article`.`comment` AS `comment`,`mc_article`.`comments` AS `comments`,`mc_article`.`commentcheck` AS `commentcheck`,`mc_article`.`posttime` AS `posttime`,`mc_article`.`title` AS `title`,`mc_article`.`title2` AS `title2`,`mc_article`.`content` AS `content`,`mc_article`.`flag` AS `flag`,`mc_article`.`cateid` AS `cateid`,`mc_article`.`sourceid` AS `sourceid`,`mc_article`.`reurl` AS `reurl`,`mc_article`.`hits` AS `hits`,`mc_article`.`author` AS `author`,`mc_article`.`from` AS `from`,`mc_article`.`keyword` AS `keyword`,`mc_article`.`order` AS `order`,`mc_article`.`memo` AS `memo`,`mc_article`.`pic1` AS `pic1`,`mc_article`.`pic2` AS `pic2`,`mc_article`.`userid` AS `userid`,`mc_article`.`html` AS `html`,`mc_article`.`ishtml` AS `ishtml`,`mc_article`.`area` AS `area`,`mc_article`.`custom1` AS `custom1`,`mc_article`.`custom2` AS `custom2`,`mc_article`.`custom3` AS `custom3`,`mc_article`.`custom4` AS `custom4`,`mc_article`.`custom5` AS `custom5`,`mc_article`.`res_id` AS `res_id`,`mc_article`.`special` AS `special`,`mc_article`.`area1` AS `area1`,`mc_article`.`area2` AS `area2`,`mc_article`.`area3` AS `area3`,`mc_article`.`area4` AS `area4`,`mc_article`.`area5` AS `area5`,`mc_article`.`isvideo` AS `isvideo`,`mc_article`.`titlecolor` AS `titlecolor`,`mc_article`.`url` AS `url`,`mc_article`.`notshowlist` AS `notshowlist`,`mc_article_cate`.`parentid` AS `parentid`,`mc_article_cate`.`level` AS `level`,`mc_article_cate`.`title` AS `ctitle`,`mc_article_cate`.`templateid` AS `templateid`,`mc_article_cate`.`forumid` AS `forumid`,`mc_article_cate`.`catetemplateid` AS `catetemplateid`,`mc_article_cate`.`dir` AS `dir`,`mc_article_cate`.`kind` AS `kind`,`mc_article_cate`.`pagesize` AS `pagesize`,`mc_article_cate`.`specialid` AS `specialid`,`mc_article_cate`.`url` AS `curl` from (`mc_article` join `mc_article_cate` on((`mc_article`.`cateid` = `mc_article_cate`.`id`)));