本帖最后由 猪喜 于 2014-5-29 19:45 编辑
本贴旨在抛砖引玉,大概讲解一下添加日志DIY模块的方法,也希望广大会员能设计出更多更好的模块分享出来。首页,效果如下图:
功能是显示会员的博客分类,日志归档,还有搜索博主文章。
2. 涉及到的文件
两个文件,1是 lang_space.php (语言文件)、2是function_space.php(所有的DIY模块程序都在这里)
3. 填加以上三个模块方法
首先,修改lang_space.php , 找到 'blockdata' 在数组中添加:- 'hansearch'=>'搜索博文','gerenfenlei'=>'个人分类','guidang'=>'日志归档'
复制代码 再添加几个语言项:
- 'hansearch' => '搜博文',
- 'gerenfenlei'=>'个人分类',
- 'allclass' =>'全部分类',
- 'noclass' => '未分类',
- 'guidang'=>'日志归档',
复制代码
之后修改 function_space.php,添加3个case,如下:
- case 'hansearch':
- $han_search = array('uid'=>$uid);
- $html .= lang('space', 'hansearchform', $han_search);
- break;
- case 'gerenfenlei':
- $uids[0] = $uid;
- $count = C::t('home_blog')->count_all_by_search(null, $uids, null, null, $gthot, null, null, null, null, null, $privacyfriend, null, null, null, null);
- $html .= '<ul class="cat_list"><li><a href="home.php?mod=space&uid='.$uid.'&do=blog&view=me&from=space">'.lang('space', 'allclass').'</a> ['.$count.']</li>';
- $query = C::t('home_class')->fetch_all_by_uid($uid);
- foreach($query as $value) {
- //$classarr[$value['classid']] = $value['classname'];
- $count = C::t('home_blog')->count_all_by_search(null, $uids, null, null, $gthot, null, null, null, null, null, $privacyfriend, null, null, null, $value['classid']);
- $html .= "<li><a href='home.php?mod=space&uid=".$uid."&do=blog&view=me&from=space&classid=".$value['classid']."'>".$value['classname']."</a> [".$count."]</li>";
- }
- $count = C::t('home_blog')->count_all_by_search(null, $uids, null, null, $gthot, null, null, null, null, null, $privacyfriend, null, null, null, -1);
- $html .= "<li><a href='home.php?mod=space&uid=".$uid."&do=blog&view=me&from=space&classid=-1'>".lang('space', 'noclass')."</a> [".$count."]</li>";
- $html .="</ul>";
- break;
- case 'guidang':
- $data_blog = C::t('home_blog')->fetch_all_by_uid($uid);
- $array_date = array();
- $html .= '<dl class="cundang">';
- foreach($data_blog as $key => $value) {
- $array_date[date("Y",$value['dateline'])][date("m",$value['dateline'])] = $array_date[date("Y",$value['dateline'])][date("m",$value['dateline'])] + 1;
- //$html .= $value['dateline']."<br>";
- }
- foreach ($array_date as $key => $value){
- $html .= '<dt><b>'.$key."</b></dt>";
- foreach ($value as $key2 => $value2){
- $y=$key;
- $m=$key2;
- $d=date("d",strtotime($key.$key2."01"));
- $t0=date('t',strtotime($key.$key2."01")); // 本月一共有几天
- $t1=mktime(0,0,0,$m,1,$y); // 创建本月开始时间
- $t2=mktime(23,59,59,$m,$t0,$y); // 创建本月结束时间
- $html .= "<dd><a href='home.php?mod=space&uid=".$uid."&do=blog&view=me&from=space&starttime=".$t1."&endtime=".$t2."'>".$key2.lang('space', 'month')."(".$value2.")</a></dd>";
- }
- }
- $html .= '</dl>';
- break;
复制代码
对应的 lang_space.php 里也加一行针对搜索框的语句如下:
- 'hansearchform' => '<form action="home.php" method="get">
- <input type="hidden" name="mod" value="space">
- <input type="hidden" name="do" value="blog">
- <input type="hidden" name="view" value="me">
- <input type="hidden" name="uid" value="{uid}">
- <input type="hidden" name="from" value="space">
- <dl class="cat_blogsearch">
- <dd>
- <input type="text" style="padding:2px; width:100px;" value="" name="searchkey" id="keyword">
- <span class="bts_h"><span><button type="button" onclick="if($(\'keyword\').value) this.form.submit();">搜索</button></span></span>
- </dd>
- </dl>
- </form>',
复制代码
以上就是全过程!
|