前面发了一篇门户首页调用文章列表,这里发下调用帖子列表的代码。 这个代码放到门户首页index.htm模板中
<!--{eval require './source/function/function_post.php';}-->
<!--{eval require './config/config_global.php';}-->
<!--{eval $prefix=$_config['db']['1']['tablepre'] }-->
<!--{eval $pagesize = 10;}-->
<!--{eval $amount=0;}-->
<!--{eval $res = mysql_query("SELECT COUNT(*) as count FROM ".$prefix."forum_thread t1 LEFT OUTER JOIN  ".$prefix."forum_threadimage t3 ON t1.tid = t3.tid WHERE t1.displayorder >- 1 AND t3.attachment <> ''");}-->
<!--{eval while($re=mysql_fetch_array($res)) $amount=$re['count']}-->
<!--{eval $pagecount = $amount ? (($amount < $pagesize) ? 1 : (($amount % $pagesize) ? ((int)($amount / $pagesize) + 1) : ($amount / $pagesize))) : 0; }-->
<!--{eval $page = !empty($_G['gp_page']) ? max(1, intval($_G['gp_page'])) : 1;}-->
<!--{eval $page = $page > $pagecount ? 1 : $page;}-->
<!--{eval $startlimit = ($page - 1) * $pagesize;}-->
<!--{eval $multipage = multi($amount, $pagesize, $page, 'portal.php?', $pagecount);}-->
<!--{eval $res = mysql_query("SELECT t1.tid,t1.fid,t2.`name`,t1.author,t1.authorid,t1.`subject`,t4.message,t1.views,t1.replies,from_unixtime(t1.dateline) as dateline,t3.attachment FROM ".$prefix."forum_thread t1 LEFT OUTER JOIN  ".$prefix."forum_forum t2 ON t1.fid = t2.fid LEFT OUTER JOIN  ".$prefix."forum_threadimage t3 ON t1.tid = t3.tid LEFT OUTER JOIN  ".$prefix."forum_post t4 ON t1.tid = t4.tid WHERE t1.displayorder >- 1 AND t3.attachment<> '' AND t4.`first` > 0 ORDER BY t1.dateline DESC LIMIT $startlimit, $pagesize");}-->
复制代码
调用列表开始:
<!--{eval while($re1=mysql_fetch_array($res)) {}-->
<a href="forum.php?mod=viewthread&tid=$re1[tid]"><!--帖子链接-->
<!--{if $re1[attachment]}--><!--如果图片附件存在-->
<img src="$_G[setting][attachurl]forum/$re1[attachment]" width="120" height="auto"><!--本地存储图片附件路径-->
<!--{/if}-->
</a>
<h3><a href="forum.php?mod=viewthread&tid=$re1[tid]" title="$article[title]">$re1[subject]</a></h3><!--帖子链接、标题-->
<p><!--{eval echo messagecutstr($re1['message'],150)}--></p><!--帖子摘要150字符-->
<a href="forum.php?mod=forumdisplay&fid=$re1[fid]" class="article-info-cat z">$re1[name]</a><!--板块链接、板块名-->
<em class="sprit z">/</em>
<a href="home.php?mod=space&uid=$re1[authorid]" class="z">$re1[author]</a><!--帖子作者链接、作者用户名-->
<em class="sprit z">/</em>
<span class="article-info-date z">$re1[dateline]</span><!--帖子发表时间-->
<span class="article-info-num y"><i></i>$re1[replies]</span><!--帖子评论数-->
<span class="article-info-view y"><i></i>$re1[views]</span><!--帖子点击数-->
<!--{eval }}-->
<div class="pages cl">$multipage</div><!--帖子列表分页-->
复制代码
以上就可以成功调用了。 说明: 以上代码调用的是含有图片附件的主题,如果想要调用所有,删掉第一步代码最后的 AND t3.attachment,可调用到无图片附件帖。 <!--{eval $pagesize = 10;}-->是每10条分页。 我这里测试的结果是共有8页,不知道怎么能改变调用总数。 ---------------------------------------------------------------------- 另一个代码,这个好像也没控制住总数,这是调用全部帖子:
<!--{eval require './source/function/function_post.php';}-->
<!--{eval $pagesize = 9;}--> 
<!--{eval $amount=0;}--> 
<!--{eval $res = mysql_query("select count(*) as count from pre_forum_post where fid in(select fid from pre_forum_forum where status=1 and type='forum') and bbcodeoff<>-1");}--> 
<!--{eval while($re=mysql_fetch_array($res)) $amount=$re['count']}--> 
<!--{eval $pagecount = $amount ? (($amount < $pagesize) ? 1 : (($amount % $pagesize) ? ((int)($amount / $pagesize) + 1) : ($amount / $pagesize))) : 0; }-->
<!--{eval $page = !empty($_G['gp_page']) ? max(1, intval($_G['gp_page'])) : 1;}--> 
<!--{eval $page = $page > $pagecount ? 1 : $page;}--> 
<!--{eval $startlimit = ($page - 1) * $pagesize;}--> 
<!--{eval $multipage = multi($amount, $pagesize, $page, 'portal.php?', $pagecount);}--> 
<!--{eval $res = mysql_query("select t1.tid,t1.views,t1.author,t1.subject,FROM_UNIXTIME(t1.dateline,'%Y') as year,FROM_UNIXTIME(t1.dateline,'%m') as month,FROM_UNIXTIME(t1.dateline,'%d') as day,t2.message,t3.attachment,t4.name,t4.fid from pre_forum_thread t1 left join pre_forum_post t2 on t1.tid=t2.tid left join pre_forum_threadimage t3 on t1.tid=t3.tid left join pre_forum_forum t4 on t1.fid=t4.fid where t1.displayorder<> -1 and t3.attachment<>' ' order by t1.dateline desc LIMIT $startlimit, $pagesize");}--> 
<!--{eval $src=""}-->
<!--{eval while($re1=mysql_fetch_array($res)) {}-->  
<div class="page-container">
        <div class="postmetadata">
                <span class="meta-date">
                        <a href="forum.php?mod=viewthread&&tid=$re1['tid']" title="$re1['subject']">
                                <span class="month">$re1['month']月</span>
                                <span class="day">$re1['day']</span>
                                <span class="year">$re1['year']</span>
                        </a>
                </span>
                <span class="meta-comments">
                        <a href="forum.php?mod=viewthread&&tid=$re1['tid']" title="$re1['subject']" class="comments-count">$re1['views']</a>
                        <a href="forum.php?mod=viewthread&&tid=$re1['tid']" title="$re1['subject']">Comment</a>
                </span>
                <span class="meta-author">
                        <span>by<br />$re1['author']</span>
                </span>
        </div>
  <div class="post-contents">
    <div class="thumbnail">
            <a href="forum.php?mod=viewthread&&tid=$re1['tid']" title="$re1['subject']"><img src="data/attachment/forum/$re1['attachment']"/></a>
    </div>
    <h3 class="entry-title">
            <a href="forum.php?mod=viewthread&&tid=$re1['tid']" title="$re1['subject']">$re1['subject']</a>
    </h3>
    <div class="post-category">来自于<a href="forum.php?mod=forumdisplay&fid=$re1['fid']">$re1['name']</a></div>
    <div class="post-content">
            <!--{eval $src=messagecutstr($re1['message'],300)}--> 
            <p>$src</p>
    </div>
  </div>
</div>
<!--{eval }}--> 
<div class="pags c1"><div id="pag"> $multipage </div></div>

声明:有的资源均来自网络转载,版权归原作者所有,如有侵犯到您的权益 请联系邮箱:123456@qq.com 我们将配合处理!

原文地址:discuz 首页调用帖子列表带分页发布于2023-04-14 17:43:23

相关推荐