Home > CMS Tutorial > PHPCMS > How to display the category name in front of the front article list in phpcms

How to display the category name in front of the front article list in phpcms

王林
Release: 2020-02-06 14:56:04
Original
2320 people have browsed it

How to display the category name in front of the front article list in phpcms

1. Open phpcms\caches\caches_commons\caches_data\category_content_1.cache.php

return array (
  1 => 
  array (
    'catid' => '1',
    'siteid' => '1',
    'type' => '1',
    'modelid' => '0',
    'parentid' => '0',
    'arrparentid' => '0',
    'child' => '1',
    'arrchildid' => '1,2,3,5,162',
    'catname' => '网站介绍',
    'style' => '',
    'image' => '',
    'description' => '',
    'parentdir' => '',
    'catdir' => 'about',
    'url' => '/html/about/',
    'items' => '0',
    'hits' => '0',
    'setting' => 'array (
  \'ishtml\' => \'1\',
  \'template_list\' => \'default\',
  \'page_template\' => \'page\',
  \'meta_title\' => \'\',
  \'meta_keywords\' => \'\',
  \'meta_description\' => \'\',
  \'category_ruleid\' => \'1\',
  \'show_ruleid\' => \'\',
  \'repeatchargedays\' => \'1\',
)',

category_content_1.cache.php
Copy after login

You can see that the detailed information of all column categories is cached here, among which There is what we need

'catname' => 'Website introduction',

2. Open phpcms\modules\content\classes\content_tag.class.php

/**
     * 列表页标签
     * @param $data
     */
    public function lists($data) {
        $catid = intval($data['catid']);
        if(!$this->set_modelid($catid)) return false;
        if(isset($data['where'])) {
            $sql = $data['where'];
        } else {
            $thumb = intval($data['thumb']) ? " AND thumb != ''" : '';
            if($this->category[$catid]['child']) {
                $catids_str = $this->category[$catid]['arrchildid'];
                $pos = strpos($catids_str,',')+1;
                $catids_str = substr($catids_str, $pos);
                $sql = "status=99 AND catid IN ($catids_str)".$thumb;
            } else {
                $sql = "status=99 AND catid='$catid'".$thumb;
            }
        }
        $order = $data['order'];

        $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');

content_tag.class.php
Copy after login

3. Add the following code after the above code

$TYPES = getcache('category_content_1','commons');//获取类别缓存2         
    foreach ($return as $key=>$v) {                                       
$return[$key][typename]=$TYPES[$v['catid']]['catname'];//给lists标签返回的数组中增加一个类别字段
}
Copy after login

4. Frontend call method

{$v[typename]}
Copy after login

Recommended related articles and tutorials:phpcms tutorial

The above is the detailed content of How to display the category name in front of the front article list in phpcms. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template