emlog博文调用方式总汇(三)
[ 2015/06/30, Emlog , 3043阅, 0评 ]

8.调取某个或多个标签下的所有文章

<?php
//调取某个或多个标签下的所有文章
function get_tagBlog($tagname,$num){
	$tags = explode(",",$tagname);
	$Tag_Model = new Tag_Model();
	$db = MySql::getInstance();
	foreach($tags as $a):
		$blogIdStr = $Tag_Model->getTagByName($a);
		echo '<h3><a href='.Url::tag($a).'>'.$a.'</a></h3>';
		echo '<ul>';
		$sql = "SELECT title,gid,date FROM ".DB_PREFIX."blog WHERE gid in ($blogIdStr) order by date DESC limit 0,$num";
		$list = $db->query($sql);
		while($row = $db->fetch_array($list)){
			echo '<li>'.gmdate('Y-n-j',$row['date']).'<a href='.Url::log($row['gid']).'>'.$row[title].'</a></li>';
		}
		echo '</ul>';
	endforeach;
}?>

使用:

<?php get_tagBlog('呵呵',10);?>
<?php get_tagBlog('呵呵,哈哈',10);?>

QQ截图20170118170258.jpg

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