在dedecms開發(fā)中,經(jīng)常會遇到循環(huán)輸出一個頂級欄目下的所有二級欄目,循環(huán)出二級欄目標(biāo)題、欄目內(nèi)容標(biāo)題鏈接等信息。
例,如圖的欄目規(guī)劃:
循環(huán)輸出 工程案例 中的 4個子欄目及內(nèi)容,并且循環(huán)出子欄目的標(biāo)題,如圖:最終效果
代碼如下:
{dede:channelartlist typeid='58' row='5'}
<div class="fullBlock">
<div class="title"><a href="{dede:field name='typeurl'/}" target="_blank">更多..</a><aside>{dede:field name='typename'/} {dede:channel type='son' noself='1'} <a href='[field:typelink/]'>[field:typename/]</a> {/dede:channel}</aside></div>
<div class="imglist">
{dede:arclist row='4' titlelen='80' } <a href="[field:arcurl/]" target="_blank" title="[field:title/]"><img src="[field:litpic/]" /></a> {/dede:arclist}
</div>
</div>
<div class="clear"></div>
{/dede:channelartlist}
1、指定channelartlist標(biāo)簽,設(shè)置typeid='58',row自定義設(shè)定。
2、循環(huán)欄目標(biāo)題與內(nèi)容
3、插入{dede:channel type='son' noself='1'} <a href='[field:typelink/]'>[field:typename/]</a> {/dede:channel}標(biāo)簽,type設(shè)置為son,子菜單。
4、注意,noself=‘1’是一個自定義標(biāo)識,是因為dedecms有一個不知道真正目的的方法,在《include\taglib\channel.lib.php》文件中的第108行:
//如果用子欄目模式,當(dāng)沒有子欄目時顯示同級欄目
if($type=='son' && $noself=='0' && $reid!=0 && $totalRow==0)
{
$sql = "SELECT id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath
FROM `ig_arctype` WHERE reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line ";
$dsql->SetQuery($sql);
$dsql->Execute();
}
5、這里的$noself=='0'是我自定義添加的,還要在第36行填寫上這個標(biāo)簽的獲取方式:
$attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|,cacheid|,noself|0";
在最后追加noself|0,默認(rèn)是0,開啟這個方法,在使用noself=‘1’時則當(dāng)前欄目沒有子欄目時,不讀取同級欄目。
真實(shí)案例詳見我公司網(wǎng)站作品: 哈爾濱天地人裝飾工程有限公司
哈爾濱品用軟件有限公司致力于為哈爾濱的中小企業(yè)制作大氣、美觀的優(yōu)秀網(wǎng)站,并且能夠搭建符合百度排名規(guī)范的網(wǎng)站基底,使您的網(wǎng)站無需額外費(fèi)用,即可穩(wěn)步提升排名至首頁。歡迎體驗最佳的哈爾濱網(wǎng)站建設(shè)。
