再说一遍其实并不是说一定要门户首页,其他页面也可以用。
下面以自定义可diy页面来演示“调用帖子列表带分页+多图显示”另一种方法。
新建三个文件,根目录下test.php入口文件、模板目录portal目录里test.htm模板文件和thread_list.php数据查询文件。惯例无CSS样式。
展开一步步说:
1.新建test.php文件,放到根目录,代码如下:- <?php
- define('CURSCRIPT', 'portal');//定义常量,用于body标签的id选择器名称,与本身文件名相同(不带后缀),可在导航栏实现当前高亮。
- define('CURMODULE', 'test');//定义常量,用于body标签的class(类)选择器名称,门户首页为该命名,可以更换,可选
- require './source/class/class_core.php';//引入系统核心文件
- $Discuz = & discuz_core::instance();//以下代码为创建及初始化对象
- $discuz->cachelist = $cachelist;
- $discuz->init();
- loadcache('diytemplatename');
- $navtitle = '这里定义单页的标题';//可选
- $metakeywords = '这里定义单页的关键词';//可选
- $metadescription ='这里定义单页的描述内容';//可选
- include template('diy:portal/test');
- ?>
复制代码
2.新建test.htm文件,放到模板目录portal文件夹里,代码如下:- <!--{template common/header}-->
- <!--{eval require_once("template/模板目录/portal/thread_list.php");}-->
- <ul>
- <li{if $_GET['order']=='dateline' || $_GET['order']==''} class="a"{/if}><a href="test.php?order=dateline">时间<span></span></a></li>
- <li{if $_GET['order']=='replies'} class="a"{/if}><a href="test.php?order=replies">回复<span></span></a></li>
- <li{if $_GET['order']=='views'} class="a"{/if}><a href="test.php?order=views">查看<span></span></a></li>
- <li{if $_GET['order']=='digest'} class="a"{/if}><a href="test.php?order=digest">精华<span></span></a></li>
- </ul>
- <div class="thread minh" style="position: relative;">
- <!--{eval $list_count=0;}-->
- <!--{loop $manylist $thread}-->
- <!--{eval $list_count+=1;}-->
- <div class="threadlist">
- <div class="threadlist_stat threadlist_stat_hot">
- <a href="forum.php?mod=viewthread&tid=$thread[tid]" title="$thread[views] 个查看">$thread[views]</a>
- </div>
- <div class="threadlist_title"
- <div class="right">
- <a href="forum.php?mod=viewthread&tid=$thread[tid]" onclick="atarget(this)" title="$thread[subject]">$thread[subject]</a>
- <!--{if $thread['attachment'] == 2}--><img src="static/image/filetype/image_s.gif" alt="attach_img" title="图片附件" align="absmiddle"/><!--{/if}-->
- </div>
- <div class="threadlist_message"><!--{echo cutstr($thread['message'],300)}--></div>
- <!--{if $thread['attachment'] == 2}-->
- <!--{eval $table='forum_attachment_'.substr($thread['tid'], -1);}-->
- <!--{eval $query = DB::fetch_all("SELECT aid,tid,description,filename FROM ".DB::table($table)." WHERE tid='$thread[tid]' AND isimage!=0 ORDER BY `dateline` DESC LIMIT 0,12"); }-->
- <!--{eval $thread['pics']=count($query);}-->
- <div class="threadlist_imglist{if $_G['cookie']['threadthumbhide']} dn{/if}">
- <!--{eval $i=1}-->
- <!--{loop $query $pic}-->
- <!--{if $i<6}-->
- <div><a href="forum.php?mod=viewthread&tid=$thread[tid]#aimg_$pic[aid]"><img src="{eval echo(getforumimg($pic[aid],0,120,80))}" alt="{if $pic[description]}$pic[description]{else}$pic[filename]{/if}" title="{if $pic[description]}$pic[description]{else}$pic[filename]{/if}"/></a></div>
- <!--{/if}-->
- <!--{eval $i++}-->
- <!--{/loop}-->
- </div>
- <!--{/if}-->
- <div class="threadlist_info">
- <div class="lastreply">
- <a href="forum.php?mod=redirect&tid=$thread[tid]&goto=lastpost#lastpost">$thread[lastposter] @ <span title="">{echo date('Y-m-d', $thread['dateline']);}</span></a>
- </div>
- <a href="home.php?mod=space&uid=$thread[authorid]">$thread[author]</a> @ {echo date('Y-m-d', $thread['dateline']);}
- <span class="pipe">|</span><span class="greencolor"><a href="forum.php?mod=forumdisplay&fid=$thread[fid]"><strong>$thread[name]</strong></a></span>
- </div>
- </div>
- <!--{/loop}-->
- </div>
- <!--{if $allnum>$num}--><div class="nextpage"><a href="javasctipt:;">下一页</a></div><!--{/if}-->
- </div>
- $pagenav
- <!--{template common/footer}-->
复制代码
以上代码里注意改文字“模板目录”为自己的模板目录名。
3.新建thread_list.php文件,放到模板目录里portal文件夹内,代码如下:
相关阅读:
discuz 门户文章列表多图显示
discuz 门户首页调用帖子列表带分页+多图显示(之一) |