search
HomeCMS TutorialPHPCMSHow to display only specified columns on the phpcms homepage

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++}
        <div class="box cat-area" {if $num%2!=0}style=" margin-right:10px"{/if}>
          <h5 id="r-a-nbsp-href-r-nbsp-class-more-更多-a">{$r}<a href="{$r}" class="more">更多>></a></h5>
             <div class="content">
             {pc:content  action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"}
             {loop $info $v}
              <p>
               <img  src="/static/imghwm/default1.png"  data-src="{thumb($v,90,0)}"  class="lazy"      style="max-width:90%"  style="max-width:90%"/ alt="How to display only specified columns on the phpcms homepage" >
                    <strong><a   target="_blank" title="{$v[&#39;title&#39;]}"{title_style($v)}>{str_cut($v[&#39;title&#39;],28)}</a></strong><br />{str_cut($v[&#39;description&#39;],100)}
                </p>
              {/loop}
              {/pc}               
                <div class="bk15 hr"></div>
                {pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"}
                <ul class="list lh24 f14">
                {loop $info $v}
                 <li>·<a href="{$v[&#39;url&#39;]}" target="_blank" title="{$v[&#39;title&#39;]}"{title_style($v)}>{str_cut($v[&#39;title&#39;],40)}</a></li>
                {/loop}
                </ul>
                {/pc}
            </div>
        </div>
        {if $num%2==0}<div class="bk10"></div>{/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[&#39;catid&#39;]==3 }<?php continue; ?>{/if} //排除某个栏目
          {php $num++}
        <div class="box cat-area" {if $num%2!=0}style=" margin-right:10px"{/if}>
          <h5 id="r-a-nbsp-href-r-nbsp-class-more-更多-a">{$r}<a href="{$r}" class="more">更多>></a></h5>
             <div class="content">
             {pc:content  action="lists" catid="$r" order="updatetime DESC" thumb="1" num="1" return="info"}
             {loop $info $v}
              <p>
               <img  src="/static/imghwm/default1.png"  data-src="{thumb($v,90,0)}"  class="lazy"      style="max-width:90%"  style="max-width:90%"/ alt="How to display only specified columns on the phpcms homepage" >
                    <strong><a   target="_blank" title="{$v[&#39;title&#39;]}"{title_style($v)}>{str_cut($v[&#39;title&#39;],28)}</a></strong><br />{str_cut($v[&#39;description&#39;],100)}
                </p>
              {/loop}
              {/pc}               
                <div class="bk15 hr"></div>
                {pc:content action="lists" catid="$r" num="5" order="id DESC" return="info"}
                <ul class="list lh24 f14">
                {loop $info $v}
                 <li>·<a href="{$v[&#39;url&#39;]}" target="_blank" title="{$v[&#39;title&#39;]}"{title_style($v)}>{str_cut($v[&#39;title&#39;],40)}</a></li>
                {/loop}
                </ul>
                {/pc}
            </div>
        </div>
        {if $num%2==0}<div class="bk10"></div>{/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 = &#39;0&#39;, $siteid = &#39;&#39;) { 
        if (empty($siteid)) $siteid = get_siteid(); 
        $category = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;); 
        foreach($category as $id=>$cat) { 
                if($cat[&#39;siteid&#39;] == $siteid && ($parentid === NULL || $cat[&#39;parentid&#39;] == $parentid) && ($type === NULL || $cat[&#39;type&#39;] == $type)) $subcat[$id] = $cat; 
                if($self == 1 && $cat[&#39;catid&#39;] == $parentid && !$cat[&#39;child&#39;])  $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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft