Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[已解决] HOME首页头部增加7条精选推荐日志方法

[复制链接]
sybgood 发表于 2010-4-14 09:37:54 | 显示全部楼层 |阅读模式
1.给UCHOME_BLOG表增加tuijian int(1)和tjsj(datetime)字段.
2.修改source\network.php中代码:

//日志
//$cachefile = S_ROOT.'./data/cache_network_blog.txt';
//if(check_network_cache('blog')) {
//        $bloglist = unserialize(sreadfile($cachefile));
//} else {
        $sqlarr = mk_network_sql('blog',
                array('blogid', 'uid'),
                array('hot','viewnum','replynum'),
                array('dateline'),
                array('dateline','viewnum','replynum','hot')
        );
        extract($sqlarr);

        //隐私
        $wherearr[] = "main.friend='0'";
       
        //显示数量
        $shownum = 6;
       
        $query = $_SGLOBAL['db']->query("SELECT main.*, field.*
                FROM ".tname('blog')." main
                LEFT JOIN ".tname('blogfield')." field ON field.blogid=main.blogid
                WHERE ".implode(' AND ', $wherearr)."
                ORDER BY main.{$order} $sc LIMIT 0,$shownum");
        $bloglist = array();
        while ($value = $_SGLOBAL['db']->fetch_array($query)) {
                $value['message'] = getstr($value['message'], 86, 0, 0, 0, 0, -1);
                $value['subject'] = getstr($value['subject'], 50, 0, 0, 0, 0, -1);
                $bloglist[] = $value;
        }
        if($_SGLOBAL['network']['blog']['cache']) {
                swritefile($cachefile, serialize($bloglist));
        }
//}
foreach($bloglist as $key => $value) {
        realname_set($value['uid'], $value['username']);
        $bloglist[$key] = $value;
}

//精选推荐

        $sqlarr = mk_network_sql('blog',
                array('blogid', 'uid'),
                array('hot','viewnum','replynum'),
                array('dateline'),
                array('dateline','viewnum','replynum','hot')
        );
        extract($sqlarr);

        //隐私
        $wherearr[] = "main.friend='0'";
       
        //显示数量
        $shownum1 = 7;
       
        $query = $_SGLOBAL['db']->query("SELECT main.*, field.*
                FROM ".tname('blog')." main
                LEFT JOIN ".tname('blogfield')." field ON field.blogid=main.blogid
                WHERE ".implode(' AND ', $wherearr)." AND tuijian=1
                ORDER BY main.tjsj desc LIMIT 0,$shownum1");
        $bloglist1 = array();
        while ($value = $_SGLOBAL['db']->fetch_array($query)) {
                $value['message'] = getstr($value['message'], 86, 0, 0, 0, 0, -1);
                $value['subject'] = getstr($value['subject'], 50, 0, 0, 0, 0, -1);
                $bloglist1[] = $value;
        }
        if($_SGLOBAL['network']['blog']['cache']) {
                swritefile($cachefile, serialize($bloglist1));
        }


function msubstr($str, $start, $len) {
$tmpstr ="";
$strlen = $start + $len;
for($i = 0; $i < $strlen; $i++) {
if(ord(substr($str, $i, 1)) > 0xa0) {
$tmpstr .= substr($str, $i, 2);
$i++;
} else
$tmpstr .= substr($str, $i, 1);
}
return $tmpstr;
}



foreach($bloglist1 as $key => $value) {
        realname_set($value['uid'], $value['username']);
        $value['subject']=msubstr($value['subject'],0,40);
        $bloglist1[$key] =$value;
}

3.修改template\default\network.htm和network.css增加推荐版块,network.htm推荐版块代码如下:

<div class="main_right">
    <div class="bt">
      <h4>精选推荐</h4>
    </div>
    <ul class="tj_list">
        <!--{loop $bloglist1 $key $value}-->       
        <li><span class="red1">[推荐]</span> <a href="space.php?uid=$value[uid]&do=blog&id=$value[blogid]"

target="_blank">$value[subject]</a></li>
        <!--{/loop}-->
    </ul>
  </div>

4.后台日志管理增加推荐功能:
修改admin\admincp_blog.php中

if($_GET['op'] == 'tuijian') {
        //推荐日志
        $tjrzid=$_GET['id'];
        $_SGLOBAL['db']->query("UPDATE ".tname('blog')." SET tuijian=1,tjsj=now() WHERE blogid='$tjrzid'");
        cpmessage('do_tjsuccess', 'admincp.php?

ac=blog&orderby='.$orderby.'&ordersc=desc&perpage='.$perpage.'&page='.$page.'&username='.$_GET

['username'].'&searchsubmit='.$_GET['searchsubmit']);
}

修改tpl\blog.htm中

                        <td>
                                <a href="admincp.php?ac=blog&op=tuijian&username=$_GET[username]&searchsubmit=$_GET

[searchsubmit]&id=$value[blogid]&orderby=blogid&ordersc=desc&perpage=$perpage&page=$page">推荐</a>&nbsp;<a href="cp.php?

ac=blog&op=edit&blogid=$value[blogid]" target="_blank">编辑</a>&nbsp;
                                <a href="admincp.php?ac=comment&id=$value[blogid]&idtype=blogid">评论</a>
                        </td>
103091443 发表于 2010-6-5 02:47:46 | 显示全部楼层
有没图片 看看的啊~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-11-25 13:01 , Processed in 0.020144 second(s), 3 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表