1.调用随机文章
<?php //随机文章 function get_randlog($num){ $Log_Model = new Log_Model(); $randLogs = $Log_Model->getRandLog($num);?> <?php foreach($randLogs as $value): ?> <a href="<?php echo Url::log($value['gid']); ?>" title="<?php echo $value['title']; ?>" ><img src="<?php get_thum($value['gid']); ?>"/></a> <?php endforeach; ?> <?php }?>
2.调用页面内容
<?php //调用页面内容 function html_page($id,$echo){ $result = mysql_fetch_array(mysql_query("SELECT * FROM ".DB_PREFIX."blog WHERE gid ='$id'")); return $result[$echo]; }?>
使用:
<?php echo html_page("8","content"); ?>
“8”为该页面的id。“content”为字段名。
3.多功能博文调用(推荐)
<?php //多功能博文调用 function eflyBlogList($way,$num){ //最新 if($way=="new"){ $order = "hide='n' and type='blog' order by date DESC"; //$order = "hide='n' and type='blog' order by top DESC,date DESC"; } //随机 if($way=="rand"){ $order = "hide='n' and type='blog' order by rand()"; } //浏览量 if($way=='views'){ $order = "hide='n' and type='blog' order by views DESC"; } //置顶 if($way=='top'){ $order = "hide='n' and type='blog' and top='y' order by top DESC,date DESC"; } //30天热门 if($way=='hot'){ $time = time(); $order = "hide='n' and type='blog' and date > $time - 30*24*60*60 order by views DESC"; } //评论量 if($way=='comnum'){ $order = "hide='n' and type='blog' order by comnum DESC"; } $db = MySql::getInstance(); $sql = "select * from ".DB_PREFIX."blog where $order limit 0,$num"; $log = $db->query($sql); while($row = $db->fetch_array($log)){ $row['title'] = htmlspecialchars($row['title']); ?> <li> <img src="<?php get_thum($row['gid']);?>"/> <h4><a href="<?php echo Url::log($row['gid']); ?>"><?php echo $row['title']; ?></a></h4> 日期:<?php echo gmdate('Y-m-d', $row['date']); ?> 分类:<?php blog_sort($row['gid']); ?> 浏览:<?php echo $row['views']; ?> 评论:<?php echo $row['comnum']; ?> </li> <?php }?> <?php }?>
使用方法:
<?php eflyBlogList("new",6);?>
4.相关文章调用
<?php //文章详情页下相关文章 function related_logs($logid,$sortid){ $related_log_type = 'sort';//调用类型,sort为分类,tag为标签; $related_log_sort = 'views_desc';//排列方式 $related_log_num = '10'; //显示文章数 $DB = MySql::getInstance(); $CACHE = Cache::getInstance(); $sql = "SELECT gid,title FROM ".DB_PREFIX."blog WHERE hide='n' AND type='blog'"; if($related_log_type == 'tag'){ $log_cache_tags = $CACHE->readCache('logtags'); $Tag_Model = new Tag_Model(); $related_log_id_str = '0'; foreach($log_cache_tags[$logid] as $key => $val){ $related_log_id_str .= ','.$Tag_Model->getTagByName($val['tagname']); } $sql .= " AND gid!=$logid AND gid IN ($related_log_id_str)"; }else{ $sql .= " AND gid!=$logid AND sortid=$sortid"; } switch($related_log_sort){ case 'views_desc':{ $sql .= " ORDER BY views DESC";break; } case 'views_asc':{ $sql .= " ORDER BY views ASC";break; } case 'comnum_desc':{ $sql .= " ORDER BY comnum DESC";break; } case 'comnum_asc':{ $sql .= " ORDER BY comnum ASC";break; } case 'rand':{ $sql .= " ORDER BY rand()"; break; } } $sql .= " LIMIT 0,$related_log_num"; $related_logs = array(); $query = $DB->query($sql); while($row = $DB->fetch_array($query)){ $row['gid'] = intval($row['gid']); $row['title'] = htmlspecialchars($row['title']); $related_logs[] = $row; } $out = ''; if(!empty($related_logs)){ foreach($related_logs as $val){ $out .= "<li><a href=\"".Url::log($val['gid'])."\">{$val['title']}</a></li>"; } } echo $out; }?>
在echo_log.php适当位置使用:
<?php related_logs($logid,$sortid);?>
说明:可按浏览量、评论量、随机等三种形式调用与当前文章同分类或者同标签的其他文章。
有朋自远方来...评论一下呗O(∩_∩)O