列表的方法

Posted ninama

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了列表的方法相关的知识,希望对你有一定的参考价值。

Phpcms调用全站最新文章需要修改文件:\\phpcms\\modules\\content\\classes\\content_tag.class.php,找到以下函数:

/**
      * 列表页标签
      * @param $data
      */
     public function lists($data)  
         $catid = ($data[\'catid\']); 
         if(!$this->set_modelid($catid)) return false; 
         if(isset($data[\'where\']))  
             $sql = $data[\'where\']; 
          else  
             $thumb = ($data[\'thumb\']) ? " AND thumb != \'\'" : \'\'; 
             if($this->category[$catid][\'child\'])  
                 $catids_str = $this->category[$catid][\'arrchildid\']; 
                 $pos = ($catids_str,\',\')+1; 
                 $catids_str = ($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\'); 
                          
         //调用副表的数据
         if (isset($data[\'moreinfo\']) && ($data[\'moreinfo\']) == 1)  
             $ids = array(); 
             foreach ($return as $v)  
                 if (isset($v[\'id\']) && !emptyempty($v[\'id\']))  
                     $ids[] = $v[\'id\']; 
                  else  
                     continue; 
                  
              
             if (!emptyempty($ids))  
                 $this->db->table_name = $this->db->table_name.\'_data\'; 
                 $ids = (\'\\\',\\\'\', $ids); 
                 $r = $this->db->select("`id` IN (\'$ids\')", \'*\', \'\', \'\', \'\', \'id\'); 
                 if (!emptyempty($r))  
                     foreach ($r as $k=>$v)  
                         if (isset($return[$k])) $return[$k] = ($v, $return[$k]); 
                      
                  
              
          
         return $return; 
      

修改为:

/**
      * 列表页标签
      * @param $data
      */
     public function lists($data)  
         $catid = ($data[\'catid\']); 
          
         if(isset($data[\'where\']))  
             $sql = $data[\'where\']; 
          else  
             $thumb = ($data[\'thumb\']) ? " AND thumb != \'\'" : \'\'; 
             if(!emptyempty($catid))  
                 if(!$this->set_modelid($catid)) return false; 
                 if($this->category[$catid][\'child\'])  
                     $catids_str = $this->category[$catid][\'arrchildid\']; 
                     $pos = ($catids_str,\',\')+1; 
                     $catids_str = ($catids_str, $pos); 
                     $sql = "status=99 AND catid IN ($catids_str)".$thumb; 
                  else  
                     $sql = "status=99 AND catid=\'$catid\'".$thumb; 
                  
              
             else  
                 $sql = "status=99".$thumb; 
              
                  
          
         $order = $data[\'order\']; 
  
         $return = $this->db->select($sql, \'*\', $data[\'limit\'], $order, \'\', \'id\'); 
                          
         //调用副表的数据
         if (isset($data[\'moreinfo\']) && ($data[\'moreinfo\']) == 1)  
             $ids = array(); 
             foreach ($return as $v)  
                 if (isset($v[\'id\']) && !emptyempty($v[\'id\']))  
                     $ids[] = $v[\'id\']; 
                  else  
                     continue; 
                  
              
             if (!emptyempty($ids))  
                 $this->db->table_name = $this->db->table_name.\'_data\'; 
                 $ids = (\'\\\',\\\'\', $ids); 
                 $r = $this->db->select("`id` IN (\'$ids\')", \'*\', \'\', \'\', \'\', \'id\'); 
                 if (!emptyempty($r))  
                     foreach ($r as $k=>$v)  
                         if (isset($return[$k])) $return[$k] = ($v, $return[$k]); 
                      
                  
              
          
         return $return; 
      

修改代码后,即能调取全站最新文章。
调用方法:

pc:content action="lists" num="10" order="id DESC" cache="3600"

 

以上是关于列表的方法的主要内容,如果未能解决你的问题,请参考以下文章

python如何合并两个列表?

Python列表函数和方法

Python 中删除列表元素的三种方法

列表-方法

Python面试必考重点之列表,元组和字典第九关——列表排序的方法/列表的sort方法和sorted函数的区别/倒序排列一个列表

Python list列表全部操作方法