Home page >> Related Tutorials >>Body

Zblog uses GetList to call the latest published articles and filter a certain category

Author: A little Jack    Time: 2022-08-24 08:58:54    Browse: 825   

From Lao Li next door: Recently, there was a request to call the latest 12 articles on the website and filter the articles under a certain category.

The first thing I think of naturally is to filter out articles of a certain category in foreach:

 $arry=GetList(12);     foreach ($arry as $related) {         if($related->Category->ID!=7){     echo '<a href="'.$related->Url.'">'.$ related->Title.'</ a>';     } }

However, this operation will reduce the number of output articles and the number of filtered articles. In the above operation, GetList (12) is used to call the latest 12 articles.

GetList() is a function commonly used in ZBLOG development. It can call articles under various conditions. ZBLOG officially upgraded GetList() after ZBP1.7 to support more query conditions.

 array( 'count'=>10,//(can be omitted) 'cat'=>1,//(can be omitted) 'auth'=>2,//(can be omitted) 'date '=>' 2020-1 ',//(can be omitted) 'tags'=>'abc',//(can be omitted) 'search '=>'s',//(can be omitted) //The following is the key key of the original $option parameter 'post_type'=>null,//Specify the type of post table to query (can be omitted) 'post_status'=>null,//Specify the status of querying the Post table (can be omitted) 'only_ontop'=>false,//specify that all are set to the top (can be omitted) 'only_not_ontop'=>false,//none of the specified values are set to the top (can be omitted) 'has_subcate'=>false,//Specify to include the descendant directory (can be omitted) 'is_related'=>false,//Specify to query related articles (can be omitted) 'order_by_meta'=>false,//Specify to sort the output results by the meta value (can be omitted) 'random'=>5,//Specify to extract 5 post table records (can be omitted) 'where_custom'=>array (array ('=', 'log_Template', '')),//customize where 'order_custom'=>array ('log_ViewNums'=>'DESC', 'log_CommNums'=>' ASC '),//custom order)

Calling the latest published articles and filtering a certain category is a no brainer.

Post code directly:

Hello, you need to log in to our account to view the hidden content, please first Sign in To view!

Note: 12 is the number of calling articles, and 1 is the classification ID to be filtered.


Text label: ZBLOG   Latest articles   Shielding classification  
 A little Jack

A little Jack https://lkba.cn

The blogger focuses on Z-Blog website construction, website optimization, computer troubleshooting, reinstallation, optimization, maintenance system, etc., QQ/WX: 2126245521 (please specify the purpose)

Related articles

Previous:

Next:

No comment for this article - Welcome

 Please fill in the verification code

Processed : 0.050 SQL : 14