SoFunction
Updated on 2025-03-05

Detailed explanation of the ideas of adding secondary navigation in PHPCMS V9

Today I looked at phpcms and found a problem when writing to the secondary navigation. The $r[arrchildid] returned when querying the information in the navigation bar does not match what I imagined. The document says it returns the subcolumn id, but it is a bit different.

The starting idea:

<ul class="nav navbar-nav">
<li class="active"><a href="{siteurl($siteid)}">front page</a></li>
{pc:content action="category" cat num="10" site order="listorder ASC"}
{loop $data $r}
{if $r[arrchildid]}
<li class="dropdown">
<a href="{$r[url]}" class="dropdown-toggle" child="{$r[arrchildid]}" data-toggle="dropdown">{$r[catname]}<b class="caret"></b></a>
<ul class="dropdown-menu">
{pc:content action="category" cat num="10" site order="listorder ASC" return="data2"}
{loop $data2 $v}
<li><a href="{$v[url]}">{$v[catname]}</a></li>
{/loop}
{/pc}
</ul> 
</li>
{/if}
{/loop}
{/pc}
</ul>

General idea: Check whether there is a subcolumn id in this document, and if so, output a secondary navigation. The fifth line in the code is to check whether there is a sub-column id under this column, but I found that when there is no sub-column, the id of the current column will be returned, so the judgment cannot achieve the expected effect, so I changed the idea and the code is as follows:

<ul class="nav navbar-nav">
<li class="active"><a href="{siteurl($siteid)}">front page</a></li>
{pc:content action="category" cat num="10" site order="listorder ASC"}
{loop $data $r}
{if $r[arrchildid] != $r[catid]}
<li class="dropdown">
<a href="{$r[url]}" class="dropdown-toggle" child="{$r[arrchildid]}" data-toggle="dropdown">{$r[catname]}<b class="caret"></b></a>
<ul class="dropdown-menu">
{pc:content action="category" cat num="10" site order="listorder ASC" return="data2"}
{loop $data2 $v}
<li><a href="{$v[url]}">{$v[catname]}</a></li>
{/loop}
{/pc}
</ul> 
</li>
{else}
<li><a href="{$r[url]}">{$r[catname]}</a></li>
{/if}
{/loop}
{/pc}
</ul>

Determine whether the obtained sub-column id is equal to the column id, which means there is no sub-column, and does not mean that there is a sub-column and the sub-column is displayed.

The above is a detailed explanation of the ideas of adding secondary navigation in PHPCMS V9 introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!