Example
The code is as follows: |
Copy code |
/** * Full-site ranking label * @ Param $ data */ Public function hits_all ($ data ){ $ This-> modelid = 12; // here it is written as a fixed model id, which is retrieved from the backend Model Management. $ This-> hits_db = pc_base: load_model ('hits _ Model '); $ This-> db-> set_model ($ this-> modelid ); $ This-> tablename = $ this-> db-> table_name; $ SQL = $ desc = $ ids = ''; $ Array = $ ids_array = array (); $ Order = $ data ['order']; $ Hitsid = 'C-'. $ this-> modelid.'-% '; $ SQL = "hitsid LIKE '$ hitsid '"; If (isset ($ data ['day']) { $ Updatetime = SYS_TIME-intval ($ data ['day']) * 86400; $ SQL. = "AND updatetime> '$ updatetime '"; } $ Hits = array (); $ Result = $ this-> hits_db-> select ($ SQL, '*', $ data ['limit'], $ order ); Foreach ($ result as $ r ){ $ Pos = strpos ($ r ['hitsid '],'-', 2) + 1; $ Ids_array [] = $ id = substr ($ r ['hitsid '], $ pos ); $ Hits [$ id] = $ r; } $ Ids = implode (',', $ ids_array ); If ($ ids ){ $ SQL = "status = 99 AND id IN ($ ids )"; } Else { $ SQL = ''; } $ This-> db-> table_name = $ this-> tablename; $ Result = $ this-> db-> select ($ SQL, '*', $ data ['limit'], '','', 'id '); Foreach ($ ids_array as $ id ){ If ($ result [$ id] ['title']! = ''){ $ Array [$ id] = $ result [$ id]; $ Array [$ id] = array_merge ($ array [$ id], $ hits [$ id]); } } Return $ array; } |
When calling:
The code is as follows: |
Copy code |
{Pc: content action = "hits_all" order = "weekviews DESC" num = "10 "} <Ul class = "softolist"> {Loop $ data $ key $ val} <Li> <a href = "{$ val ['URL']}" title = "{$ val ['title']}" >{$ val ['title']} </a> </li> {/Loop} </Ul> {/Pc} |
Example 2
① Open the phpcmsmodulescontentclassescontent_tag.class.php file;
② Locate and add the following code (the first line can be freely modified for later query ):
The code is as follows: |
Copy code |
Function sitehits ($ data ){ If (emptyempty ($ data ['siteid']) return false; $ Siteid = intval ($ data ['siteid']); $ This-> hits_db = pc_base: load_model ('hits _ Model '); $ Category_content = getcache ('Category _ content', 'commons '); $ Catid = ''; // Obtain the ID of all columns under the site Foreach ($ category_contentas $ key => $ val ){ If ($ val = $ siteid ){ $ Catid. = $ comma. $ key; $ Comma = ','; } } // Obtain the Click ranking $ R = $ this-> hits_db-> select ('catid in ('. $ catid. ')', 'hitsid ', $ data ['limit'], $ data ['order']); $ Return = array (); $ Sitemodel_model_db = pc_base: load_model ('sitemodel _ Model '); $ This-> db_config = pc_base: load_config ('database '); $ Tablepre = $ this-> db_config ['default'] ['tablepre']; Foreach ($ ras $ key ){ Preg_match_all ('/-(d +)-/', $ key ['hitsid '], $ modelid ); $ Id = substr ($ key ['hitsid'], (strpos ($ key ['hitsid'], '-', 2) + 1 )); $ Tablename = $ sitemodel_model_db-> get_one (array ('modelid' => $ modelid [1] [0]), 'tablename '); $ This-> db-> table_name = $ tablepre. $ tablename ['tablename']; $ Return [] = array_merge ($ return, $ this-> db-> get_one (array ('id' => $ id ))); } Return $ return; } |
③ Back up files to prevent overwriting during later pc program upgrade;
④ Call method of the front-end page template (example ):
As follows:
The code is as follows: |
Copy code |
{Pc: content action = "sitehits" siteid = "4" num = "10" order = "views DESC" cache = "3600"} {loop $ data $ r} "{$ R [url]}" target = "_ blank"> {$ r [title]} {/Loop} {/Pc} |