Home>Article>CMS Tutorial> How to display only specified columns on the phpcms homepage

How to display only specified columns on the phpcms homepage

angryTom
angryTom Original
2020-02-15 14:18:20 2311browse

How to display only specified columns on the phpcms homepage

How to display only specified columns on the phpcms homepage

The following code controls which columns are displayed through the column id, and the id is based on the actual situation For background query, see the explanation of the subcat function in the last attachment. Modify the code as follows:

{loop subcat(0,0,0,$siteid) $r} {if $r['catid']==1||$r['catid']==2 } //显示哪些栏目 {php $num++} 
{$r}更多>>
{pc:content action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"} {loop $info $v}

{str_cut($v['title'],28)}
{str_cut($v['description'],100)}

{/loop} {/pc}
{pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"} {/pc}
{if $num%2==0}
{/if} {/if} {/loop}

In addition to specifying specific columns, we can also use the exclusion method to display specific columns

V9 Exclusion Method of a certain column

{loop subcat(0,0,0,$siteid) $r} {if $r['catid']==3 }{/if} //排除某个栏目 {php $num++} 
{$r}更多>>
{pc:content action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"} {loop $info $v}

{str_cut($v['title'],28)}
{str_cut($v['description'],100)}

{/loop} {/pc}
{pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"} {/pc}
{if $num%2==0}
{/if} {/loop}

{loop subcat(0,0,0,$siteid) $r}{/loop}Function explanation:

/** * 获取子栏目 * @param $parentid 父级id * @param $type 栏目类型 1为单网页类型,0为栏目类型;(查看phpcms的mysql数据库可以看到) * @param $self 是否包含本身 0为不包含 * @param $siteid 站点id */ function subcat($parentid = NULL, $type = NULL,$self = '0', $siteid = '') { if (empty($siteid)) $siteid = get_siteid(); $category = getcache('category_content_'.$siteid,'commons'); foreach($category as $id=>$cat) { if($cat['siteid'] == $siteid && ($parentid === NULL || $cat['parentid'] == $parentid) && ($type === NULL || $cat['type'] == $type)) $subcat[$id] = $cat; if($self == 1 && $cat['catid'] == $parentid && !$cat['child']) $subcat[$id] = $cat; } return $subcat; }

PHP Chinese website, a large number of freePHPCMS tutorials, welcome to learn online!

The above is the detailed content of How to display only specified columns on the phpcms homepage. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn