首頁 > php教程 > php手册 > PHPCMS V9 新增二級導航

PHPCMS V9 新增二級導航

WBOY
發布: 2016-10-22 00:00:10
原創
1107 人瀏覽過

今天看了看phpcms 寫到二級導航時發現點問題,查詢導航欄的資訊時返回的$r[arrchildid]與自己想像的不符,文檔上說是返回子欄位id但是卻有些不同。

開始的思路:

<span style="color: #008080;"> 1</span>  <ul <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">nav navbar-nav</span><span style="color: #800000;">"</span>>
<span style="color: #008080;"> 2</span>     <li <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">active</span><span style="color: #800000;">"</span>><a href=<span style="color: #800000;">"</span><span style="color: #800000;">{siteurl($siteid)}</span><span style="color: #800000;">"</span>>首页</a></li>
<span style="color: #008080;"> 3</span>        {pc:content action=<span style="color: #800000;">"</span><span style="color: #800000;">category</span><span style="color: #800000;">"</span> catid=<span style="color: #800000;">"</span><span style="color: #800000;">0</span><span style="color: #800000;">"</span> num=<span style="color: #800000;">"</span><span style="color: #800000;">10</span><span style="color: #800000;">"</span> siteid=<span style="color: #800000;">"</span><span style="color: #800000;">$siteid</span><span style="color: #800000;">"</span> order=<span style="color: #800000;">"</span><span style="color: #800000;">listorder ASC</span><span style="color: #800000;">"</span><span style="color: #000000;">}
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">          {loop $data $r}
</span><span style="color: #008080;"> 5</span>           {<span style="color: #0000ff;">if</span> $r[arrchildid]<span style="color: #000000;">}
</span><span style="color: #008080;"> 6</span>             <li <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown</span><span style="color: #800000;">"</span>>
<span style="color: #008080;"> 7</span>               <a href=<span style="color: #800000;">"</span><span style="color: #800000;">{$r[url]}</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown-toggle</span><span style="color: #800000;">"</span> child=<span style="color: #800000;">"</span><span style="color: #800000;">{$r[arrchildid]}</span><span style="color: #800000;">"</span> data-toggle=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown</span><span style="color: #800000;">"</span>>{$r[catname]}<b <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">caret</span><span style="color: #800000;">"</span>></b></a>
<span style="color: #008080;"> 8</span>                  <ul <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown-menu</span><span style="color: #800000;">"</span>>
<span style="color: #008080;"> 9</span>                   {pc:content action=<span style="color: #800000;">"</span><span style="color: #800000;">category</span><span style="color: #800000;">"</span> catid=<span style="color: #800000;">"</span><span style="color: #800000;">$r[catid]</span><span style="color: #800000;">"</span> num=<span style="color: #800000;">"</span><span style="color: #800000;">10</span><span style="color: #800000;">"</span> siteid=<span style="color: #800000;">"</span><span style="color: #800000;">$siteid</span><span style="color: #800000;">"</span> order=<span style="color: #800000;">"</span><span style="color: #800000;">listorder ASC</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">return</span>=<span style="color: #800000;">"</span><span style="color: #800000;">data2</span><span style="color: #800000;">"</span><span style="color: #000000;">}
</span><span style="color: #008080;">10</span> <span style="color: #000000;">                    {loop $data2 $v}
</span><span style="color: #008080;">11</span>                       <li><a href=<span style="color: #800000;">"</span><span style="color: #800000;">{$v[url]}</span><span style="color: #800000;">"</span>>{$v[catname]}</a></li>
<span style="color: #008080;">12</span>                     {/<span style="color: #000000;">loop}
</span><span style="color: #008080;">13</span>                   {/<span style="color: #000000;">pc}
</span><span style="color: #008080;">14</span>                  </ul>  
<span style="color: #008080;">15</span>             </li>
<span style="color: #008080;">18</span>           {/<span style="color: #0000ff;">if</span><span style="color: #000000;">}
</span><span style="color: #008080;">19</span>         {/<span style="color: #000000;">loop}
</span><span style="color: #008080;">20</span>      {/<span style="color: #000000;">pc}
</span><span style="color: #008080;">21</span> </ul>
登入後複製

大致思路:查詢該文件下是否有子欄id,如果有則輸出二級導覽。程式碼中第5行是偵測該欄位下是否有子欄位id,但我發現當沒有子欄位時會傳回目前欄位目的id導致判斷無法達到預期的效果,所以改變思路,程式碼如下:

<span style="color: #008080;"> 1</span>  <ul <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">nav navbar-nav</span><span style="color: #800000;">"</span>>
<span style="color: #008080;"> 2</span>     <li <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">active</span><span style="color: #800000;">"</span>><a href=<span style="color: #800000;">"</span><span style="color: #800000;">{siteurl($siteid)}</span><span style="color: #800000;">"</span>>首页</a></li>
<span style="color: #008080;"> 3</span>       {pc:content action=<span style="color: #800000;">"</span><span style="color: #800000;">category</span><span style="color: #800000;">"</span> catid=<span style="color: #800000;">"</span><span style="color: #800000;">0</span><span style="color: #800000;">"</span> num=<span style="color: #800000;">"</span><span style="color: #800000;">10</span><span style="color: #800000;">"</span> siteid=<span style="color: #800000;">"</span><span style="color: #800000;">$siteid</span><span style="color: #800000;">"</span> order=<span style="color: #800000;">"</span><span style="color: #800000;">listorder ASC</span><span style="color: #800000;">"</span><span style="color: #000000;">}
</span><span style="color: #008080;"> 4</span> <span style="color: #000000;">         {loop $data $r}
</span><span style="color: #008080;"> 5</span>            {<span style="color: #0000ff;">if</span> $r[arrchildid] !=<span style="color: #000000;"> $r[catid]}
</span><span style="color: #008080;"> 6</span>              <li <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown</span><span style="color: #800000;">"</span>>
<span style="color: #008080;"> 7</span>                <a href=<span style="color: #800000;">"</span><span style="color: #800000;">{$r[url]}</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown-toggle</span><span style="color: #800000;">"</span> child=<span style="color: #800000;">"</span><span style="color: #800000;">{$r[arrchildid]}</span><span style="color: #800000;">"</span> data-toggle=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown</span><span style="color: #800000;">"</span>>{$r[catname]}<b <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">caret</span><span style="color: #800000;">"</span>></b></a>
<span style="color: #008080;"> 8</span>                  <ul <span style="color: #0000ff;">class</span>=<span style="color: #800000;">"</span><span style="color: #800000;">dropdown-menu</span><span style="color: #800000;">"</span>>
<span style="color: #008080;"> 9</span>                     {pc:content action=<span style="color: #800000;">"</span><span style="color: #800000;">category</span><span style="color: #800000;">"</span> catid=<span style="color: #800000;">"</span><span style="color: #800000;">$r[catid]</span><span style="color: #800000;">"</span> num=<span style="color: #800000;">"</span><span style="color: #800000;">10</span><span style="color: #800000;">"</span> siteid=<span style="color: #800000;">"</span><span style="color: #800000;">$siteid</span><span style="color: #800000;">"</span> order=<span style="color: #800000;">"</span><span style="color: #800000;">listorder ASC</span><span style="color: #800000;">"</span> <span style="color: #0000ff;">return</span>=<span style="color: #800000;">"</span><span style="color: #800000;">data2</span><span style="color: #800000;">"</span><span style="color: #000000;">}
</span><span style="color: #008080;">10</span> <span style="color: #000000;">                      {loop $data2 $v}
</span><span style="color: #008080;">11</span>                         <li><a href=<span style="color: #800000;">"</span><span style="color: #800000;">{$v[url]}</span><span style="color: #800000;">"</span>>{$v[catname]}</a></li>
<span style="color: #008080;">12</span>                       {/<span style="color: #000000;">loop}
</span><span style="color: #008080;">13</span>                      {/<span style="color: #000000;">pc}
</span><span style="color: #008080;">14</span>                   </ul>  
<span style="color: #008080;">15</span>               </li>
<span style="color: #008080;">16</span>            {<span style="color: #0000ff;">else</span><span style="color: #000000;">}
</span><span style="color: #008080;">17</span>               <li><a href=<span style="color: #800000;">"</span><span style="color: #800000;">{$r[url]}</span><span style="color: #800000;">"</span>>{$r[catname]}</a></li>
<span style="color: #008080;">18</span>            {/<span style="color: #0000ff;">if</span><span style="color: #000000;">}
</span><span style="color: #008080;">19</span>         {/<span style="color: #000000;">loop}
</span><span style="color: #008080;">20</span>       {/<span style="color: #000000;">pc}
</span><span style="color: #008080;">21</span> </ul>
登入後複製

判斷取得到的子欄id是否等於該欄位id,等於則表示沒有子欄目,不等於則表示有子欄位且顯示子欄位

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板