Zblog calls the method of the latest published article and filters a certain category

skill 2 years ago Lao Li next door Last edited on 2022-06-22 10:34:30

Today, a user asked me how to filter a certain category on the homepage of a certain topic, but he wanted to throw this article directly to him:

About the correct method of ZBLOG homepage filtering a classified article and reconstructing paging

But it suddenly occurred to me that my topic is a CMS topic, and this section on the home page is the latest 12 articles of the called website.

So I thought of filtering out articles of a certain category directly in foreach.

like this:

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

It does implement filtering and classification, but the problem is that the number of output articles will reduce the number of filtering.

That is to say, the number of output articles=12 - the number of filtered articles.

If the 12 recently published articles are all in this filtered section, the number of output articles is directly equal to 0!

Although the development principle of zb is to use it, it is really useless!

So I went to the group to ask the leader. The following is the communication process:

Me: Boss, can GetList() divide a category?

Boss: Yes!

Me: But CV?

Boss: You can read the documents!

Me: Cat?

Boss: No, can you read the second part of the tail?

Me: I know!

 Zblog calls the latest published articles and filters a certain category. Page 1

Back to modern times, check the documentation and find that the array of GetList() contains the parameter where_custom, which can be used to customize conditions.

Then I suddenly realized!

Post code directly:

 $arry=GetList(array('count'=>12,'where_custom' => array(array('<>', 'log_CateID', 1)))); foreach ($arry as $related) {     echo '<a href="'.$related->Url.'">'.$ related->Title.'</ a>'; }

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

So far, the problem is solved!


This article is written by@ Lao Li next door Published on March 12, 2022 on Yeluzi Blog , unless otherwise specified, all articles in this blog are original, please retain the source for reprinting.
comment (3)
 visitor
 Cat C Blog
Thank you, boss. It has been collected
· From Hangzhou, Zhejiang Province · reply
 Li Yang's Blog
Can the number of calls 12 be changed to the number of articles displayed on the list page set by the website?
· From Liaoning Province · reply
 Brother Cat
six hundred and sixty-six
· From Chengdu, Sichuan Province · reply
Top