phpcms导航菜单的写法
PHP打印方法:
{php print_r(变量);}
<?php print_r(变量);?>
1.
<div class="webnav"> {pc:get sql="select catname,url from v9_category order by listorder ASC" } <ul class="clearfix"> <!--<li><a href="{siteurl($siteid)}">首页</a></li>--> {loop $data $r} <li><a href="{$r[url]}">{$r[catname]}</a></li> {/loop} </ul> {/pc} {php echo runhook('glogal_menu')} </div>
加粗的写法:从栏目表查出catname 和 url字段值 按照listorder 正序排列
{pc:get sql="select catname,url from v9_category order by listorder ASC" } 可以改写成
{pc:get sql="select*from v9_category order by listorder ASC" }
2.导航选中状态:
{if $catid == $r['catid']}class="current"{/if}
例如:
<div class="webnav"> {pc:get sql="select * from v9_category order by listorder ASC" } <ul class="clearfix"> {if $catid} <li><a href="{siteurl($siteid)}">首页</a></li> {else} <li class="current"><a href="{siteurl($siteid)}">首页</a></li> {/if} {loop $data $r} <li {if $catid==$r['catid']}class="current"{/if}><a href="{$r[url]}">{$r[catname]}</a></li> {/loop} </ul> {/pc} {php echo runhook('glogal_menu')} </div>
当然首页那也可以这样:
<li {if empty($catid)}class="current"{/if}><a href="{siteurl($siteid)}">首页</a></li>
$catid //当前栏目ID
$r['catid'] //循环出来的