|  | 
 
| 今天我告訴大家一些在織夢dedecms里面調(diào)用 discuz論壇帖子的一些方法,這些方法都是好不容易從網(wǎng)上搜來的,這次一次奉獻(xiàn)給大家啦。 首先要注意的是下面的代碼中都有table="bbs_threads"這句。這句不是適用所有網(wǎng)站的,這個(gè)地方cbd是你論壇的表前綴名稱,大家根據(jù)自己的論壇修改成合適的表前綴名。再者,我是把織夢和discuz 論壇放在一個(gè)數(shù)據(jù)庫里面的,才開始放在兩個(gè)數(shù)據(jù)庫,整合了半天不成功,不知道是什么原因。后面放在一個(gè)數(shù)據(jù)庫里面成功了。但是沒有在放到兩個(gè)數(shù)據(jù)庫里面做測試,大家也可以測試下,告訴我結(jié)果了。按道理來說不限制放進(jìn)同一個(gè)數(shù)據(jù)庫才合理些!最后m-d H:M 帶表是發(fā)布的時(shí)間,如果只要(日-月)時(shí)間格式的,把 H:M去掉即可。
 
 1、論壇最新主題調(diào)用代碼如下:
 
 {dede:loop table="bbs_threads" sort="tid" row="10"}
 <a href="/bbs/viewthread.php?tid=[field:tid /]">
 ·[field:subject function="cn_substr('@me',30)" /]([field:lastpost function="date('m-d H:M','@me')" /])</a>
 <br/>
 {/dede:loop}
 
 這個(gè)連接地址你可以寫相對路徑,也可以寫絕對路徑。
 
 如果是discuz動態(tài)論壇,鏈接地址如http://bbs.xxx.com/viewthread.php?tid=[field:tid /]
 
 如果是discuz靜態(tài)論壇,連接地址如http://bbs.xxx.com/thread-[field:tid /]-1-1.html
 
 2、論壇指定版塊帖子調(diào)用方法:
 
 { dede:loop table="bbs_threads" if="fid=1 or fid=2 and displayorder!=-1" sort="tid" row="6" }
 <a href="/bbs/viewthread dot php?tid=[field:tid /]" target="_blank">
 ·[field:subject function="cn_substr(' @ me',50)" /] </a>
 <br/>
 { /dede:loop }
 
 其中的fid=1 or fid=2是論壇主題分類id,可以按照自己要求來修改,如果是一個(gè)分類就直接寫fid=x
 
 3、論壇調(diào)精華主題調(diào)用代碼如下:
 
 {dede:loop table="bbs_threads" if="displayorder!=-1" sort="tid" row="10"}
 <a href="/bbs/viewthread.php?tid=[field:tid /]">
 ·[field:subject function="cn_substr('@me',30)" /]([field:lastpost function="date('m-d H:M','@me')" /])</a>
 <br/>
 {/dede:loop}
 
 如果想調(diào)用某個(gè)板塊的精華主題代碼如下:
 
 {dede:loop table="bbs_threads" if="fid=5 and displayorder!=-1" sort="tid" row="10"}
 <a href="/bbs/viewthread.php?tid=[field:tid /]">
 ·[field:subject function="cn_substr('@me',30)" /]([field:lastpost function="date('m-d H:M','@me')" /])</a>
 <br/>
 {/dede:loop}
 
 其中的fid=5是論壇主題分類id,可以按照自己要求來修改,
 
 如果想調(diào)用論壇所有的板塊的最新精華主題只要去掉fid=5 and 就可以了。
 
 4、調(diào)用的帖子列表這可以按查看次數(shù)排序,代碼如下:
 
 {dede:loop table="bbs_threads"  sort="views" row="10"}
 <a href="/dz/viewthread.php?tid=[field:tid /]">
 ·[field:subject function="cn_substr('@me',30)" /]([field:lastpost function="date('m-d H:M','@me')" /])</a>
 <br/>
 {/dede:loop}
 其中sort="views" 就是控制按照查看次數(shù)排序的代碼
 
 5、論壇置頂版塊帖子調(diào)用方法舉例:
 
 { dede:loop table="bbs_threads" sort="dateline" if="fid='3' and typeid='51'" row="10" }
 <a href="/a/bbs/viewthread dot php?tid=[field:tid /]" target="_blank">
 ·[field:subject function="cn_substr(' @ me',30)" /]</a> <br>
 { /dede:loop }
 
 6、論壇版塊名稱調(diào)用方法:
 
 { dede:loop table="bbs_forums" sort="displayorder" row="16" col="4" }
 <a href="/bbs/viewthread dot php?fid=[field:fid /]">·[field:name function="cn_substr(' @me',30)" /] </a>
 { /dede:loop }
 
 注:這種方法這個(gè)還有點(diǎn)問題,它會將論壇分區(qū)、版塊都調(diào)出來。望達(dá)人改進(jìn)!
 
 附:dedecms的LOOP 標(biāo)記規(guī)則
 
 功能說明:用于調(diào)用任意表的數(shù)據(jù),一般用于調(diào)用論壇貼子之類的操作
 
 適用范圍:所有模板
 
 基本語法:
 
 { dede:loop table=' sort='' row='' if='' }
 
 [1] table 表示查詢的數(shù)據(jù)表
 
 [2] sort 用于排序的字段 也可以加"views"(查看次數(shù)排列)
 
 [3] row 返回結(jié)果的條數(shù)
 
 [4] if 查詢條件
 
 7、調(diào)用論壇帖子中的圖片方法,網(wǎng)上搜到的,我自己還沒有做測試。
 
 {dede:sql sql="SELECT`bbs_attachments`.`aid`,`bbs_attachments`.`attachment`,`bbs_threads`.`tid`, `bbs_threads`.`fid`,`bbs_threads`.`subject` FROM `bbs_attachments` LEFT JOIN `bbs_threads`
 
 ON`bbs_threads`.`tid`=`bbs_attachments`.`tid` WHERE `bbs_attachments`.`readperm`='0' AND`displayorder`>='0' AND `filetype`='image/pjpeg' GROUP BY tid LIMIT 0,1 "}
 <a href="/bbs/viewthread.php?tid=[field:tid /]">
 <img src="/bbs/attachments/[field:attachment/]" ALT="[field:subject/]" width="100" height="80" border="0" />
 </A>
 {/dede:sql}
 
 | 
 |