emlog博文调用方式总汇(二)
[ 2015/06/20, Emlog , 3039阅, 0评 ]

5.调取指定分类的最新文章

<?php
//调取指定分类的最新文章
function get_sortlist($sortid,$num){
	$db = MySql::getInstance();
	$sql = "SELECT * FROM ".DB_PREFIX."blog WHERE type='blog' AND sortid IN (".$sortid.") AND hide='n' ORDER BY `date` DESC LIMIT 0,".$num."";
	$list = $db->query($sql);
	while($row = $db->fetch_array($list)){
	?>
    <li><span><?php echo gmdate('Y-m-d',$row['date']);?></span><a href="<?php echo Url::log($row['gid']);?>"><?php echo $row['title'];?></a></li>	
	<?php }?>
<?php } ?>

单个分类:

<?php get_list(1,10);?>或者<?php get_list("1",10);?>

多个分类:

<?php get_list("1,3",10);?>

6.调取指定分类的最新文章和分类名称及链接

<?php
//调取指定分类的最新文章和分类名称及链接
function get_CMSlist($sortid,$num){
	$db = MySql::getInstance();
	$sql1 = "SELECT sortname FROM ".DB_PREFIX."sort WHERE sid=".$sortid;
	$s = $db->query($sql1);
	$sortname = $db->fetch_array($s);?>
    <h3>分类:<a href="<?php echo Url::sort($sort);?>"><?php echo $sortname['sortname'];?></a></h3>
	<?php 
    $sql2 = "SELECT gid,title,date FROM ".DB_PREFIX."blog WHERE sortid=".$sortid."  AND hide='n' ORDER BY `date` DESC LIMIT $num";
    $list = $db->query($sql2);
    while($row = $db->fetch_array($list)){
    ?>
    <li><span><?php echo gmdate('Y-m-d',$row['date']);?></span><a href="<?php echo Url::log($row['gid']);?>"><?php echo $row['title'];?></a></li>
<?php }?>
<?php }?>

每次只能调用一个分类,调用方式:

<?php get_CMSlist(1,10);?>

7.配合“模板设置”插件,调取指定多个分类的最新文章和分类名称及链接

可在后台设置要显示的分类和文章数量。

<?php
function get_CMSlist_more(){
	$db = MySql::getInstance();
	global $CACHE; 
	$sort_cache = $CACHE->readCache('sort');
	foreach(_g('CMSsortid') as $key => $i){
		$key = $key+1;
		$out .='<h3><a href="'.Url::sort($i).'">'.$sort_cache[$i]['sortname'].'</a></h3>';
		$out .='<ul>';
		$num = _g('CMSsortlogNum');
		$num = $num - 0;
		$logs = $db->query ("SELECT * FROM ".DB_PREFIX."blog WHERE sortid='$i' AND type='blog' AND hide='n' order by date DESC limit 0,{$num}");
		while ($trow = $db->fetch_array($logs)){
			$date = gmdate('Y-m-d', $trow['date']);
			//$trow['title'] = mb_substr($trow['title'],0,180,'utf-8');
			//$img = get_thum($trow['gid']);
			$out .='<li><span>'.$date.'</span><a href="'.Url::log($trow['gid']).'">'.$trow['title'].'</a></li>';
		}
		$out .='</ul>';
	}
	echo $out;
}?>

options.php中:

<?php
/*@support tpl_options*/
!defined('EMLOG_ROOT') && exit('access deined!');
$options = array(

'CMSsortid' => array(
'type' =>'sort',
'name' =>'CMS分类id',
'description' =>'"不选"为不显示,排序请在分类中进行',
'multi' =>'true',
),

'CMSsortlogNum' => array(
'type' =>'text',
'name' =>'CMS分类文章数量',
'default' =>'10',
),

);
?>

使用:

<?php get_CMSlist_more();?>

有朋自远方来...评论一下呗O(∩_∩)O