Usage:
First, we need to create the include. Php file in our topic directory. If so, add the script directly.
The code is as follows: |
Copy code |
/** * Get the article list * @ Param int $ count quantity * @ Param null $ cate Category ID * @ Param null $ auth user ID * @ Param null $ date * @ Param null $ tags tag * @ Param null $ search keywords * @ Param null $ order sorting * @ Param null $ option * @ Return array | mixed */ Function TcgetList ($ count = 10, $ cate = null, $ auth = null, $ date = null, $ tags = null, $ search = null, $ option = null, $ order = null ){ Global $ zbp; If (! Is_array ($ option )){ $ Option = array (); } If (! Isset ($ option ['only _ ontop ']) $ Option ['only _ ontop '] = false; If (! Isset ($ option ['only _ not_ontop ']) $ Option ['only _ not_ontop '] = false; If (! Isset ($ option ['has _ subcate ']) $ Option ['has _ subcate'] = false; If (! Isset ($ option ['is _ related']) $ Option ['is _ related'] = false; If ($ option ['is _ related']) { $ At = $ zbp-> GetPostByID ($ option ['is _ related']); $ Tags = $ at-> Tags; If (! $ Tags) Return array (); $ Count = $ count + 1; } If ($ option ['only _ ontop '] = true ){ $ W [] = array ('=', 'log _ IsTop ', 0 ); } Elseif ($ option ['only _ not_ontop '] = true ){ $ W [] = array ('=', 'log _ IsTop ', 1 ); } $ W = array (); $ W [] = array ('=', 'log _ status', 0 ); $ Articles = array (); If (! Is_null ($ cate )){ $ Category = new Category; $ Category = $ zbp-> GetCategoryByID ($ cate ); If ($ category-> ID> 0 ){ If (! $ Option ['has _ subcate']) { $ W [] = array ('=', 'log _ cateid', $ category-> ID ); } Else { $ Arysubcate = array (); $ Arysubcate [] = array ('log _ cateid', $ category-> ID ); Foreach ($ zbp-> categorys [$ category-> ID]-> SubCategorys as $ subcate ){ $ Arysubcate [] = array ('log _ cateid', $ subcate-> ID ); } $ W [] = array ('array', $ arysubcate ); } } } If (! Is_null ($ auth )){ $ Author = new Member; $ Author = $ zbp-> GetMemberByID ($ auth ); If ($ author-> ID> 0 ){ $ W [] = array ('=', 'log _ authorid', $ author-> ID ); } } If (! Is_null ($ date )){ $ Datetime = strtotime ($ date ); If ($ datetime ){ $ Datetitle = str_replace (array ('% y %', '% m %'), array (date ('Y', $ datetime), date ('N ', $ datetime), $ zbp-> lang ['MSG '] ['Year _ month']); $ W [] = array ('between', 'log _ posttime', $ datetime, strtotime ('+ 1 month', $ datetime )); } } If (! Is_null ($ tags )){ $ Tag = new Tag; If (is_array ($ tags )){ $ Ta = array (); Foreach ($ tags as $ t ){ $ Ta [] = array ('log _ tag', '% {'. $ t-> ID. '} % '); } $ W [] = array ('Array _ like', $ ta ); Unset ($ ta ); } Else { If (is_int ($ tags )){ $ Tag = $ zbp-> GetTagByID ($ tags ); } Else { $ Tag = $ zbp-> GetTagByAliasOrName ($ tags ); } If ($ tag-> ID> 0 ){ $ W [] = array ('like', 'log _ tag', '% {'. $ Tag-> ID. '} % '); } } } If (is_string ($ search )){ $ Search = trim ($ search ); If ($ search! = ''){ $ W [] = array ('search', 'log _ content', 'log _ intro', 'log _ title', $ search ); } } If (! Empty ($ order )){ If ($ order = 'new '){ $ Order = array ('log _ posttime' => 'desc '); } If ($ order = 'Hot '){ $ Order = array ('log _ viewnums' => 'desc '); } If ($ order = 'comm '){ $ Order = array ('log _ commnums' => 'desc '); } If ($ order = 'Rand '){ $ Order = array ('rand () '=> ''); } } $ Articles = $ zbp-> GetArticleList ('*', $ w, $ order, $ count, null, false ); If ($ option ['is _ related']) { Foreach ($ articles as $ k => $ ){ If ($ a-> ID = $ option ['is _ related']) Unset ($ articles [$ k]); } If (count ($ articles) = $ count ){ Array_pop ($ articles ); } } Return $ articles; }
|
Then it is called in the interface template we need.
Popular articles
The code is as follows: |
Copy code |
{$ Array = TcgetList (10, null, 'Hot ');} <Ul id = "related"> {Foreach $ array as $ related} <Li> <span class = "time"> {$ related. time ('M-D')} </span> <span class = "title"> <a href = "{$ related. url} "title =" {$ related. title} "> {$ related. title }</a> </span> </li> {/Foreach} </Ul>
|
Call 10 popular articles
Hot comments
The code is as follows: |
Copy code |
{$ Array = TcgetList (10, null, 'comm ';} <Ul id = "related"> {Foreach $ array as $ related} <Li> <span class = "time"> {$ related. time ('M-D')} </span> <span class = "title"> <a href = "{$ related. url} "title =" {$ related. title} "> {$ related. title }</a> </span> </li> {/Foreach} </Ul> |
Use the native code of zblogphp directly. The code is as follows:
The code is as follows: |
Copy code |
/"; $ Content = $ article-> Content; Preg_match_all ($ pattern, $ content, $ matchContent ); Echo $ matchContent [1] [0]; {/Php} "/> |
The html code compiled at the front-end of the code is: , which can be added to any place you want to call.
How to call a PHP random article
No plug-ins are written. The method is as follows:
1. Open zb_system \ function \ c_system_event.php
In row 3, $ zbp-> AddBuildModule ('previous '); add $ zbp-> AddBuildModule ('sjarticles ');
In row 3, $ zbp-> AddBuildModule ('previous '); add $ zbp-> AddBuildModule ('sjarticles ');
Add:
The code is as follows: |
Copy code |
Function BuildModule_sjarticles (){ Global $ zbp; $ Articles = $ zbp-> GetArticleList ( Array ('*'), Array ('=', 'log _ type', 0), array ('=', 'log _ status', 0 )), Array ('rand () '=> ''), Array (10 ), Null ); $ S = ''; Foreach ($ articles as $ article ){ $ S. = ''. $ article-> Title .''; } Return $ s; } |
2. Open zb_system \ function \ lib \ zblogphp. php
In row 3, $ this-> RegBuildModule ('previous ', 'buildmodule _ previous'); add $ this-> RegBuildModule ('hotartices', 'buildmodule _ sjarticles ');
3. Open the database, add new data in the zbp_module table, 15 popular articles, sjarticles, 0, divsjarticles, ul, 0, system, 0
Call method: call {$ modules ['sjarticles ']. Content}