phpcms的分类名称和类别名称的调用
<p>话不多说,请看代码:</p>
<div>
<div>
<div id="highlighter_716040">
<div>
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td>
<div>
1</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
<div>
5</div>
<div>
6</div>
<div>
7</div>
<div>
8</div>
<div>
9</div>
<div>
10</div>
</td>
<td>
<div>
<div>
<code>//在需要调用的模板前写这句代码,$CATEGORYS 代表分类,$TYPE 代表类别(没有这句话,调不出来)</code>
</div>
<div>
<code>{php </code><code>$CATEGORYS</code> <code>= getcache(</code><code>'category_content_'</code><code>.</code><code>$siteid</code><code>,</code><code>'commons'</code><code>);</code><code>$TYPE</code> <code>= getcache(</code><code>'type_content'</code><code>,</code><code>'commons'</code><code>);}</code>
</div>
<div>
</div>
<div>
<code>//调用</code>
</div>
<div>
<code>{</code><code>$TYPE</code><code>[</code><code>$typeid</code><code>][</code><code>'name'</code><code>]} </code><code>//$typeid代表分类的id(在后台可以看到)</code>
</div>
<div>
<code>{</code><code>$CATEGORYS</code><code>[</code><code>$catid</code><code>]} </code><code>//$catid代表分类的id(在后台可以看到)</code>
</div>
<div>
</div>
<div>
<code>//通过子栏目的id获取父类的id和名称</code>
</div>
<div>
<code>父栏目id:{</code><code>$CATEGORY</code><code>[</code><code>$catid</code><code>]}</code>
</div>
<div>
<code>父栏目名称:{</code><code>$CATEGORYS</code><code>[</code><code>$CAT</code><code>]}</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
<div id="codetool">
<div>
<textarea></textarea>
</div>
</div>
</div>
<p>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!</p> 哇,感谢楼主的分享!正好最近在用phpcms做项目,这个分类和类别调用的问题困扰我好久了呢。
顶一个!
这个方法确实很实用,特别是那个获取父栏目名称的方法,之前我一直不知道怎么获取父类名称,现在终于有答案了。
不过我想补充一下,如果是在列表页调用当前栏目的名称,其实直接用{$catname}也可以的,不用那么麻烦。倒是像你这样先getcache确实更灵活一些,能在自定义页面或者特殊需求时用到。
另外提醒一下新手朋友们,$typeid和$catid这两个变量需要在对应的模板页面有定义才能使用哦,如果是新手的话可能需要注意这一点。
总之很实用的教程,希望能看到更多phpcms相关的教程!点赞
本帖回复于源码公社 https://ym.gs
页:
[1]