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!
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!