Emlog随机查看文章
<?php //随便看看 function sbkk_logs() { $db = MySql::getInstance(); $sql = "SELECT gid FROM ".DB_PREFIX."blog WHERE type='blog' and hide='n' ORDER BY rand() LIMIT 0,1"; $sbkk_logs_list = $db->query($sql); while($row = $db->fetch_array($sbkk_logs_list)){ echo Url::log($row['gid']); } } ?> 调用方式: <a href="<?php sbkk_logs();?>">随便看看</a>
Emlog按天数时间调用随机热门文章列表
<?php //30天按点击率排行文章 function getdatelogs($log_num) { $a=""; $b=1; $c=""; $d=1; $db = MySql::getInstance(); $time = time(); $sql = "SELECT gid,title,views,comnum FROM ".DB_PREFIX."blog WHERE type='blog' AND date > $time - 30*24*60*60 ORDER BY `views` DESC LIMIT 0,$log_num"; $list = $db->query($sql); while($row = $db->fetch_array($list)){ ?> <li><p class="text-muted"><span class="post-comments">评论 (<?php echo $row['comnum']; ?>)</span><a class="post-like"> ℃ (<span><?php echo $row['views']; ?></span>)</a></p><span class="label label-<?php echo $c+$d++;?>"><?php echo $a+$b++;?></span><a href="<?php echo Url::log($row['gid']); ?>" title="<?php echo $row['title']; ?>"><?php echo $row['title']; ?></a></li> <?php } ?> <?php } ?> 调用方式: <?php getdatelogs('5');?>“5”是显示数量,30*24*60*60为30天,如要改成7天只需要把30改为7即可,一年就改成365即可。
Emlog实现最新文章标题加摘要显示代码
<?php //首页置顶头条 function getZhidingLogs() { $db = MySql::getInstance(); $sql = "SELECT gid,title,content,date FROM ".DB_PREFIX."blog WHERE type='blog' and top='y' ORDER BY `top` DESC ,`date` DESC LIMIT 0,1"; $list = $db->query($sql); while($row = $db->fetch_array($list)){ //$row['content'] = htmlspecialchars($row['content']); $row['content'] = strip_tags($row['content']);?> <h1><a href="<?php echo Url::log($row['gid']); ?>" title="<?php echo $row['title']; ?>" target="_blank"><?php echo $row['title']; ?></a></h1> <span class="note"><?php echo mb_substr($row['content'],0,85,'utf-8'); ?>...</span><a href="<?php echo Url::log($row['gid']); ?>" class="font2_2" target="_blank">阅读全文>></a> <?php } ?> <?php } ?> 在需要的地方使用<?php getZhidingLogs();?>调用,输出摘要文字字数请自行修改<?php echo mb_substr($row['content'],0,85,'utf-8');?>这段代码中,中间的85为字数,自己根据需要调整。
Emlog两串美化代码
判断时间
<?php $t=time() - 3*24*60*60; $log_t=gmdate('Y-m-d',$$value['date']); $diy_t=date("Y-m-d",$t); if($log_t > $diy_t) echo '<img src="new.png" alt="newico" />'; ?>
判断浏览量
<?php if ($value['views'] >= 100) echo '<img src="hot.png" alt="hotico" />'; ?>
Emlog狂欢一下特效
这个不好讲,请直接访问http://lanyes.org/zuopin/615.html查看吧
Emlog所有标签列表代码
<?php require_once 'init.php'; define('TEMPLATE_PATH', TPLS_PATH.Option::get('nonce_templet').'/'); $CACHE = Cache::getInstance(); $options_cache = $CACHE->readCache('options'); extract($options_cache); $navibar = unserialize($navibar); $curpage = CURPAGE_HOME; $site_title = '所有标签列表 - '.Option::get('blogname'); $site_key = '博客标签列表'; $site_description = '博客所有标签列表页面'; include View::getView('header'); ?> <div style="background:#fff;padding:10px;display: table;height:100%"> <div style="font-size:16px;padding-bottom:5px;margin-bottom:10px;color:#0C3;border-bottom:1px solid #00aff0"> 现在位置:<a title="返回首页" href="<?php echo BLOG_URL; ?>">首页</a> ? 所有标签列表 </div> <ul> <?php global $CACHE; $tag_cache = $CACHE->readCache('tags'); ?> <?php foreach($tag_cache as $value): ?> <li style="white-space:nowrap;margin:0 10px 10px 0;float:left"> <span style="font-size:<?php echo $value['fontsize']; ?>pt; line-height:30px;border: 1px dashed #CCC;padding: 5px;border-radius: 10px;display: block;"> <a style="color:#<?php echo dechex(rand(0,16777215));?>" href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇日志"> <?php echo $value['tagname']; ?>(<?php echo $value['usenum']; ?>) </a> </span> </li> <?php endforeach; ?> </ul> </div> <div style="clear:both"></div> <?php include View::getView('footer');?>
使用方式:
在您网站的根目录下创建一个tag.php文件,然后访问即可,“tag”可以更好为您要的名字,这个随意
EMLOG调用指定多个分类文章列表代码
<?php function Get_newlogs($log_num) { $db = MySql::getInstance(); $sql = "SELECT gid,title,date,content,views FROM ".DB_PREFIX."blog WHERE type='blog' and hide='n' and sortid IN (1,2,3,4) ORDER BY `date` DESC LIMIT 0,$log_num"; $list = $db->query($sql); while($row = $db->fetch_array($list)){ ?> <li><a href="<?php echo Url::log($row['gid']); ?>"><?php echo $row['title']; ?></a></li> <?php } ?> <?php } ?> 调用方式: <?php Get_newlogs(5);?>代码中的5表示需要输出的文章列表条数。
Emlog自动获取网站Favicon图标代码并自动保存
<?php //获取友链favicon站标 function favicon_file($site_url){ $site_url = strtolower(rtrim($site_url,'/')); $site_md5 = md5($site_url); $fav_url = TEMPLATE_URL.'favicon/'; $fav_path = TEMPLATE_PATH.'favicon/'; $t = 2592000; //30天,单位:秒 if(!is_file($fav_path.$site_md5.'.png') || (time() - filemtime($fav_path.$site_md5.'.png')) > $t) { copy('http://www.google.com/s2/favicons?domain='.str_replace('http://','',$site_url),$fav_path.$site_md5.'.png'); } return $fav_url.$site_md5.'.png'; }?> 调用方式: <?php echo favicon_file($value['url']); ?>
Emlog评论实现IP显示
<?php function convertip($ip){ $dat_path = EMLOG_ROOT . '/content/templates/xiu/ip.dat'; //*数据库路径*// if (!($fd = @fopen($dat_path, 'rb'))) { return 'IP数据库文件不存在或者禁止访问或者已经被删除!'; } $ip = explode('.', $ip); $ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3]; $DataBegin = fread($fd, 4); $DataEnd = fread($fd, 4); $ipbegin = implode('', unpack('L', $DataBegin)); if ($ipbegin < 0) { $ipbegin += pow(2, 32);
}
$ipend = implode('', unpack('L', $DataEnd)); if ($ipend < 0) { $ipend += pow(2, 32); } $ipAllNum = ($ipend - $ipbegin) / 7 + 1; $BeginNum = 0; $EndNum = $ipAllNum; while ($ip1num > $ipNum || $ip2num < $ipNum) { $Middle = intval(($EndNum + $BeginNum) / 2); fseek($fd, $ipbegin + 7 * $Middle); $ipData1 = fread($fd, 4); if (strlen($ipData1) < 4) { fclose($fd); return '系统出错!'; } $ip1num = implode('', unpack('L', $ipData1)); if ($ip1num < 0) { $ip1num += pow(2, 32); } if ($ip1num > $ipNum) { $EndNum = $Middle; continue; } $DataSeek = fread($fd, 3); if (strlen($DataSeek) < 3) { fclose($fd); return '系统出错!'; } $DataSeek = implode('', unpack('L', $DataSeek . chr(0))); fseek($fd, $DataSeek); $ipData2 = fread($fd, 4); if (strlen($ipData2) < 4) { fclose($fd); return '系统出错!'; } $ip2num = implode('', unpack('L', $ipData2)); if ($ip2num < 0) { $ip2num += pow(2, 32); } if ($ip2num < $ipNum) { if ($Middle == $BeginNum) { fclose($fd); return '未知'; } $BeginNum = $Middle; } } $ipFlag = fread($fd, 1); if ($ipFlag == chr(1)) { $ipSeek = fread($fd, 3); if (strlen($ipSeek) < 3) { fclose($fd); return '系统出错!'; } $ipSeek = implode('', unpack('L', $ipSeek . chr(0))); fseek($fd, $ipSeek); $ipFlag = fread($fd, 1); } if ($ipFlag == chr(2)) { $AddrSeek = fread($fd, 3); if (strlen($AddrSeek) < 3) { fclose($fd); return '系统出错!'; } $ipFlag = fread($fd, 1); if ($ipFlag == chr(2)) { $AddrSeek2 = fread($fd, 3); if (strlen($AddrSeek2) < 3) { fclose($fd); return '系统出错!'; } $AddrSeek2 = implode('', unpack('L', $AddrSeek2 . chr(0))); fseek($fd, $AddrSeek2); } else { fseek($fd, -1, SEEK_CUR); } while (($char = fread($fd, 1)) != chr(0)) { $ipAddr2 .= $char; } $AddrSeek = implode('', unpack('L', $AddrSeek . chr(0))); fseek($fd, $AddrSeek); while (($char = fread($fd, 1)) != chr(0)) { $ipAddr1 .= $char; } } else { fseek($fd, -1, SEEK_CUR); while (($char = fread($fd, 1)) != chr(0)) { $ipAddr1 .= $char; } $ipFlag = fread($fd, 1); if ($ipFlag == chr(2)) { $AddrSeek2 = fread($fd, 3); if (strlen($AddrSeek2) < 3) { fclose($fd); return '系统出错!'; } $AddrSeek2 = implode('', unpack('L', $AddrSeek2 . chr(0))); fseek($fd, $AddrSeek2); } else { fseek($fd, -1, SEEK_CUR); } while (($char = fread($fd, 1)) != chr(0)) { $ipAddr2 .= $char; } } fclose($fd); if (preg_match('/http/i', $ipAddr2)) { $ipAddr2 = ''; } $ipaddr = "{$ipAddr1} {$ipAddr2}"; $ipaddr = preg_replace('/CZ88.Net/is', '', $ipaddr); $ipaddr = preg_replace('/^s*/is', '', $ipaddr); $ipaddr = preg_replace('/s*$/is', '', $ipaddr); if (preg_match('/http/i', $ipaddr) || $ipaddr == '') { $ipaddr = '未知'; } $ipaddr = iconv('gbk', 'utf-8//IGNORE', $ipaddr); if ($ipaddr != ' ') { return $ipaddr; } else { $ipaddr = '评论者来自火星,无法或者其所在地!'; } return $ipaddr; } ?> 调用方式: <?php echo convertip($comment['ip']); ?>,ip.dat自己从纯真官网下载好了
Emlog评论显示系统浏览器及用户操作系统
请使用http://www.emlog.net/plugin/164插件
1、下载插件并解压;
2、上传至emlog插件根目录并后台激活此插件;
3、打开你所用模板中的module.php,找到评论列表模块和子评论列表模块,在foreach和endforeach之间的合适位置插入一段显示浏览器和操作系统的代码。以官方模板为例:
找到评论列表模块和子评论列表模块的<?php echo $comment['poster']; ?>,在这之后
1.0~1.1版添加:
<?php if(function_exists('display_useragent')){display_useragent($comment['cid']);} ?>
1.2版以后添加:
<?php if(function_exists('display_useragent')){display_useragent($comment['cid'],$comment['mail']);} ?>
Emlog获取制定分类文章及数量
<?php //调用主分类和子分类文章 function lonewolf_getlogs($sortid,$log_num) { $db = MySql::getInstance(); $sql = "SELECT gid,title,date FROM ".DB_PREFIX."blog WHERE type='blog' and hide='n' and sortid in (".lonewolf_getsortids($sortid).") ORDER BY `date` DESC LIMIT 0,$log_num"; $list = $db->query($sql); while($row = $db->fetch_array($list)){ ?> <li><span><?php $log_t=gmdate('Y-m-d',$row['date']);echo $log_t;?></span><i>+</i><a title="<?php echo $row['title'];?>" href="<?php echo Url::log($row['gid']);?>"><?php echo $row['title'];?></a></li> <?php } } ?> 调用方式: <?php lonewolf_getlogs(1,16);?>“1”为分类ID,“16”为显示数量
Emlog日志列表文字显示限制
<?php $logdes = blog_tool_purecontent($value['content'], 178);?> 调用方式: <?php echo $logdes; ?>,178就是显示数量
Emlog首页置顶代码
<?php //首页置顶日志 function Home_Top_Logs() { $db = MySql::getInstance(); $sql = "SELECT gid,title,content,date FROM ".DB_PREFIX."blog WHERE type='blog' and top='y' ORDER BY `top` DESC ,`date` DESC LIMIT 0,12"; $list = $db->query($sql); while($row = $db->fetch_array($list)){ ?> <li><img src="<?php get_thum($row['gid']);?>" width="220" height="125" alt="<?php echo $row['title'];?>" /><div class="logtitle"><?php echo $row['title'];?></div><div class="logtouming"></div><div class="logbackground"><a href="<?php echo Url::log($row['gid']);?>"></a></div><div class="hot"></div></li> <?php } ?> <?php } ?> 调用方式: <?php Home_Top_Logs();?>
Emlog判断分类输出子分类ID号
<?php //判断分类输出子分类ID号 function getsortids($sortid){ global $CACHE; $sort_cache = $CACHE->readCache('sort'); $sort = $sort_cache[$sortid]; if ($sort['pid'] != 0 || empty($sort['children'])) { $fenlei_ids = $sortid; } else { $sortids = array_merge(array($sortid), $sort['children']); $fenlei_ids = implode(',', $sortids); } return $fenlei_ids; }?>
Emlog分类置顶代码
<?php //分类置顶日志 function Sort_Top_Logs($sortid) { $db = MySql::getInstance(); $sql = "SELECT gid,title,content,date,sortid FROM ".DB_PREFIX."blog WHERE type='blog' and sortop='y' and sortid in (".getsortids($sortid).") ORDER BY `sortop` DESC ,`date` DESC LIMIT 0,4"; $list = $db->query($sql); while($row = $db->fetch_array($list)){ ?> <li><img src="<?php get_thum($row['gid']);?>" width="220" height="125" alt="<?php echo $row['title'];?>" /><div class="logtitle"><?php echo $row['title'];?></div><div class="logtouming"></div><div class="logbackground"><a href="<?php echo Url::log($row['gid']);?>"></a></div><div class="hot"></div></li> <?php } ?> <?php } ?> 调用方式: <?php Sort_Top_Logs($sortid);?>
Emlog获取文章缩略图
<?php //获取文章缩略图 function get_thum($logid){ $db = MySql::getInstance(); $thum_pic = EMLOG_ROOT.'/thumpic/'.$logid.'.jpg'; if (is_file($thum_pic)) { $thum_url = BLOG_URL.'thumpic/'.$logid.'.jpg'; }else{ $sqlimg = "SELECT * FROM ".DB_PREFIX."attachment WHERE blogid=".$logid." AND (`filepath` LIKE '%jpg' OR `filepath` LIKE '%gif' OR `filepath` LIKE '%png') ORDER BY `aid` ASC LIMIT 0,1"; $img = $db->query($sqlimg); while($roww = $db->fetch_array($img)){ $thum_url=BLOG_URL.substr($roww['filepath'],3,strlen($roww['filepath'])); } if (empty($thum_url)) { srand((double)microtime()*1000000); $randval = rand(0,8); $thum_url = BLOG_URL.'content/templates/xiu/images/rand/'.$randval.'.jpg'; } } echo $thum_url; } ?>
Emlog调用网站统计代码
日志总数:
<?php echo $sta_cache['lognum'];?>
评论总数:
<?php echo $sta_cache['comnum_all'];?>
碎语总数:
<?php echo $sta_cache['twnum'];?>
运行时间:
<?php echo floor((time()-strtotime("2014-01-30"))/86400); ?>
2014-01-30替换为您博客开始时间
选择在侧边栏显示站点统计,把以上代码添加到模板文件(side.php)对应位置可以了。也可使用小劣开发的EMLOG统计插件(飞机票:http://www.emlog.net/plugin/172)
Emlog日志列表显示图片(文章有图则显示文章图)
<?php if(pic_thumb($value['content'])){ $imgsrc = pic_thumb($value['content']); }else $imgsrc = TEMPLATE_URL.'images/'.rand(1,40).'.jpg'; ?> 调用方式: <?php echo $imgsrc; ?>
Emlog评论头像显示图片
<?php $heads=array("img/logcmt/01.jpg"=>"01","img/logcmt/02.jpg"=>"02","img/logcmt/03.jpg"=>"03","img/logcmt/04.jpg"=>"04","img/logcmt/05.jpg"=>"05","img/logcmt/06.jpg"=>"06","img/logcmt/07.jpg"=>"07","img/logcmt/08.jpg"=>"08","img/logcmt/09.jpg"=>"09","img/logcmt/10.jpg"=>"10","img/logcmt/11.jpg"=>"11","img/logcmt/12.jpg"=>"12","img/logcmt/13.jpg"=>"13","img/logcmt/14.jpg"=>"14"); ?> <?php if(empty($comment['mail'])){ echo TEMPLATE_URL;echo array_rand($heads);}else{echo getGravatar($comment['mail']);} ?>
Emlog头像缓存
<?php function get_avatar($mail,$alt,$size = '60',$default='wavatar'){ $alt = strip_tags($alt); $email_md5=md5(strtolower($mail));//通过MD5加密邮箱 $cache_path=TEMPLATE_PATH."cache"; //缓存文件夹路径,需要换上你的主题目录名称 if(!file_exists($cache_path)) { mkdir($cache_path,0700); } $avatar_url=TEMPLATE_URL."cache/".$email_md5.'.jpg'; //头像相对路径 $avatar_abs_url=$cache_path."/".$email_md5.'.jpg'; //头像绝对路径 $cache_time=24*3600*7; //缓存时间为7天 if (empty($default)) $default = $cache_path. '/default.png'; if(!file_exists($avatar_abs_url) || (time()-filemtime($avatar_abs_url)) > $cache_time)//过期或图片不存在 { $new_avatar = getGravatar($mail,$size,$default); copy($new_avatar,$avatar_abs_url); } return "<img title='{$alt}' alt='{$alt}' src='{$avatar_url}' height='{$size}' width='{$size}' />"; } ?> 调用方式: <?php get_avatar($comment['mail'],"{$comment['poster']}{$comment['comment_nums']}");?>
Emlog文章页路径获取分类
<?php //文章页路径获取分类 function sortbread($sortid){ global $CACHE; $sort_cache = $CACHE->readCache('sort'); ?> <?php if (isset($sort_cache[$sortid])): ?> <?php if (isset($sort_cache[$sort_cache[$sortid]['pid']])): ?> <a href="<?php echo Url::sort($sort_cache[$sortid]['pid']); ?>"><?php echo $sort_cache[$sort_cache[$sortid]['pid']]['sortname']; ?></a> » <?php endif; ?> <a href="<?php echo Url::sort($sortid); ?>"><?php echo $sort_cache[$sortid]['sortname'];?></a> » <?php endif;?> <?php }?> 调用方式: <?php sortbread($sortid); ?>
Emlog标签作为页面关键词
<?php //标签作为页面关键词 function page_tag_key($blogid){ global $CACHE; $log_cache_tags = $CACHE->readCache('logtags'); if (!empty($log_cache_tags[$blogid])){ $tag = ''; foreach ($log_cache_tags[$blogid] as $value){ $tag .= $value['tagname'].','; } echo $tag; } }?>
留着以后备用,先收着,来源xlonewolf.net
评论 (0)