功能菜单

EMLOG博文调用方式小姿势大全

2017-9-26 0 PHP代码 蓝优
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);?>

蓝优网说明:可按浏览量、评论量、随机等三种形式调用与当前文章同分类或者同标签的其他文章。

 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();?>


本站声明

独乐乐不如众乐乐,您分享的干货是给予本站最大的支持和鼓励也是大家的福利! 本站承诺:投稿一旦通过会给予投稿人1~20元红包作为奖励,内容质量决定于你的红包数量! 正常审核时间为每天:9:00~19:00 投稿邮箱:1410469560@qq.com 提示:本站使用两种模式方法投稿:邮箱投稿与会员投稿,性质一样!

投稿须知

1.投稿可带个人QQ/Q群等宣传信息 不可带第三方网址! 2.不收录:色情/入侵/FD/反动/擦边球等相关违法内容,一旦发现直接提交网警处理。 3.不要尝试玩套路,故意教程做得不详细骗人气或软件发布后马上开启更新,发现一次永久屏蔽。 4.投稿不要群发邮件这样导致站长审核困难,发现永久拉黑投稿人邮箱不作解释! 5.为保障教程的清晰度,请使用《屏幕录像专家》这款软件进行录制。 6.请勿上传病毒木马,否则可能导致您的账号被封,IP段被封 永远无法投稿。 7.投稿信息请认真填写,我们会在后台第一时间审核,审核通过后可在首页展示您的教程。

投稿格式

标题: 内容: 截图: 你的支付宝收款账号或微信收款账号:

最终解释权归本站所有。