오늘 phpcms를 보다가 보조 네비게이션 작성 시 문제점을 발견했습니다. 네비게이션 바 정보를 쿼리할 때 반환된 $r[arrchildid]가 제가 상상한 것과 일치하지 않습니다. 돌아왔지만 좀 달랐다.
시작 아이디어:
<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와 같은지 확인합니다. 동일하면 하위 열이 없다는 의미이며 하위 열이 해당됩니다. 표시