POST TIME:2021-05-22 21:31
今天在整合dedecms和Discuz!的時(shí)候發(fā)現(xiàn)原來(lái)的調(diào)用不能用了,百度一下發(fā)現(xiàn),自從Discuz!從7.0到Discuz!X1.5后,原有的表結(jié)構(gòu)發(fā)生了變化,不僅如此,pre_forum_attachment表更是成了10個(gè)(pre_forum_attachment_0到pre_forum_attachment_9),又來(lái)的dede:loop和dede:sql調(diào)用方法顯然是不能用了,但是如何才能完美的調(diào)用論壇里面的圖片帖子呢?
研究了一下午,終于找到了方法,Discuz!在把pre_forum_attachment表編程10個(gè)后,多了一個(gè)表,即:pre_forum_threadimage,這個(gè)表是專門用來(lái)存放一個(gè)主題中的樓主貼圖片附件中,寬度最大的一張圖片,這個(gè)圖片是用來(lái)論壇后臺(tái)添加外部鏈接是選擇只讀取有圖片的帖子時(shí)所用。所以這個(gè)方便多了,感覺(jué)有點(diǎn)像dedecms里面的flag='p'。
好了,廢話一大堆,直接介紹方法:
{dede:sql sql="SELECT`pre_forum_threadimage`.`tid`,`pre_forum_threadimage`.`attachment`,`pre_forum_thread`.`subject` FROM `pre_forum_threadimage` LEFT JOIN `pre_forum_thread`ON`pre_forum_thread`.`tid`=`pre_forum_threadimage`.`tid` order by tid desc LIMIT 0,2"}{/dede:sql}
其中鏈接為:你的論壇地址:您的論壇網(wǎng)址/forum.php?mod=redirect&tid=[field:tid /]&goto=lastpost#lastpost
如果是靜態(tài)化,那么就是這樣的:您的論壇網(wǎng)址/thread-[field:tid /]-1-1.html
標(biāo)題:[field:subject/]
圖片:/data/attachment/forum/[field:attachment/]
最終就是這樣的:
{dede:sql sql="SELECT`pre_forum_threadimage`.`tid`,`pre_forum_threadimage`.`attachment`,`pre_forum_thread`.`subject` FROM `pre_forum_threadimage` LEFT JOIN `pre_forum_thread`ON`pre_forum_thread`.`tid`=`pre_forum_threadimage`.`tid` order by tid desc LIMIT 0,6"}
<dl>
<dt><a href="論壇網(wǎng)址/thread-[field:tid /]-1-1.html"{target}><img src="論壇網(wǎng)址/data/attachment/forum/[field:attachment/]" alt="[field:subject/]" /></a></dt>
<dd><a href="論壇網(wǎng)址/thread-[field:tid /]-1-1.html" title="[field:subject/]" target="_blank">[field:subject/]</a></dd>
</dl>
{/dede:sql}
下面介紹如何調(diào)用帖子,調(diào)用帖子就比較簡(jiǎn)單了,直接上代碼吧:
{dede:sql sql="select subject,tid from pre_forum_thread order by tid desc limit 0,6"}
<li><a href="論壇網(wǎng)址/thread-[field:tid /]-1-1.html" title="[field:subject /]" target="_blank">[field:subject /]</a></li>
{/dede:sql}
里面的limit 0,6這個(gè)就不用我說(shuō)了吧,order by tid desc ,這個(gè)的意思是按照tid從大到小讀取,也就是最新發(fā)表。OK。測(cè)試一下吧!順便說(shuō)一下,這樣調(diào)出來(lái)的圖片有點(diǎn)大,因?yàn)楫吘谷思掖娴氖亲顚挼囊粡堃黄铮菣?quán)益下來(lái),這樣還是比較好的,反正一般都不多!
本人也是百度、論壇等等地方找了拼湊起來(lái)的,如有不正確之處,請(qǐng)留言指出,相互交流,學(xué)習(xí)!
