官方的[!---newsnav--]有什么不足?
1、樣式死板 輸出的樣式寫死在程序里 要修改只能改官方源碼 升級時會痛苦不堪
2、有的欄目用的二級域名,比如資訊頁面,我想[!---newsnav--]顯示的是 資訊首頁>xxx>xxx 而不是 首頁>資訊>xxx>xxx,用[!---newsnav--]就實現(xiàn)不了
所以要改進,如何改進?
第一步:在e/class/userfun.php中加入下面的函數(shù)
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | //當(dāng)前位置導(dǎo)航function user_linknav($classid){ global $empire,$dbtbpre,$navclassid,$class_r,$public_r; //當(dāng)前欄目 if($classid=="selfinfo"){ if(empty($navclassid)){ $classid=0; }else{ $classid=$navclassid; //終極類別則顯示同級類別 if($class_r[$classid][islast]&&$class_r[$classid][bclassid]){ $classid=$class_r[$classid][bclassid]; } if($class_r[$classid][islast]&&empty($class_r[$classid][bclassid])){ $classid=0; } } } $query="select classname,bclassid,classpath from {$dbtbpre}enewsclass where classid=".$classid; $sql=$empire->query($query); //echo "<a href = /"//">首頁</a>"; while($r=$empire->fetch($sql)){ findparent($r[bclassid]); echo " > <a href =/"/".$r[classpath]."/">".$r[classname]."</a>"; }}//當(dāng)前位置導(dǎo)航,遞歸查詢父欄目function findparent($classid){ global $empire,$dbtbpre; $query="select classname,bclassid,classpath from {$dbtbpre}enewsclass where classid=".$classid; $sql=$empire->query($query); while($r=$empire->fetch($sql)){ findparent($r[bclassid]); $prefix=""; if($r[bclassid]){$prefix = " > ";} echo $prefix."<a href =/"/".$r[classpath]."/">".$r[classname]."</a>"; }} |
第二步:在模板里,以前寫[!---newsnav--]的地方,直接替換成<?user_linknav($GLOBALS[navclassid]);?>
這里代碼直接照搬了前輩的代碼,只是有些小改動,較之于前輩的貼子,這篇里的代碼改動了
1、findparent函數(shù)里加了一行判斷,如果是頂級欄目了,則前面不加“ > ”,否則再加
2、調(diào)用該功能時,不使用標(biāo)簽,直接寫php代碼,省去一步麻煩
前輩的貼子
blackq:[原創(chuàng)]完美替換“當(dāng)前位置導(dǎo)航” [!---newsnav--]
http://bbs.phome.net/ShowThread/?threadid=80000&forumid=31
lcj110:{最新版}完美替換“當(dāng)前位置導(dǎo)航” [!---newsnav--]
http://bbs.phome.net/ShowThread/?threadid=126337&forumid=31
新聞熱點
疑難解答