Hello,
Try this. You can add your category IDs in $excluded_categories array.
<?php
function veronika_random_items($numItems = 10, $category = array(), $withPicture = false) {
$excluded_categories = array(1,2);
$max_items = osc_get_preference('maxLatestItems@home', 'osclass');
if($max_items == '' or $max_items == 0) {
$max_items = 24;
}
$numItems = $max_items;
$withPicture = osc_get_preference('latest_picture', 'veronika_theme');
$randomOrder = osc_get_preference('latest_random', 'veronika_theme');
$premiums = osc_get_preference('latest_premium', 'veronika_theme');
$category = osc_get_preference('latest_category', 'veronika_theme');
$randSearch = Search::newInstance();
$randSearch->dao->select(DB_TABLE_PREFIX.'t_item.* ');
$randSearch->dao->from( DB_TABLE_PREFIX.'t_item use index (PRIMARY)' );
// where
$whe = DB_TABLE_PREFIX.'t_item.b_active = 1 AND ';
$whe .= DB_TABLE_PREFIX.'t_item.b_enabled = 1 AND ';
$whe .= DB_TABLE_PREFIX.'t_item.b_spam = 0 AND ';
if($premiums == 1) {
$whe .= DB_TABLE_PREFIX.'t_item.b_premium = 1 AND ';
}
$whe .= '('.DB_TABLE_PREFIX.'t_item.b_premium = 1 || '.DB_TABLE_PREFIX.'t_item.dt_expiration >= \''. date('Y-m-d H:i:s').'\') ';
if( $category <> '' and $category > 0 ) {
$subcat_list = Category::newInstance()->findSubcategories( $category );
$subcat_id = array();
$subcat_id[] = $category;
foreach( $subcat_list as $s) {
$subcat_id[] = $s['pk_i_id'];
}
$listCategories = implode(', ', $subcat_id);
$whe .= ' AND '.DB_TABLE_PREFIX.'t_item.fk_i_category_id IN ('.$listCategories.') ';
}
if(!empty($excluded_categories)) {
$excluded_categories_str = implode(', ', $excluded_categories)
$whe .= ' AND '.DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN ('.$excluded_categories_str.') ';
}
if($withPicture) {
$prem_where = ' AND ' . $whe;
$randSearch->dao->from( '(' . sprintf("select %st_item.pk_i_id FROM %st_item, %st_item_resource WHERE %st_item_resource.s_content_type LIKE '%%image%%' AND %st_item.pk_i_id = %st_item_resource.fk_i_item_id %s GROUP BY %st_item.pk_i_id ORDER BY %st_item.dt_pub_date DESC LIMIT %s", DB_TABLE_PREFIX, DB_TABLE_PREFIX, DB_TABLE_PREFIX, DB_TABLE_PREFIX, DB_TABLE_PREFIX, DB_TABLE_PREFIX, $prem_where, DB_TABLE_PREFIX, DB_TABLE_PREFIX, $numItems) . ') AS LIM' );
} else {
$prem_where = ' WHERE ' . $whe;
$randSearch->dao->from( '(' . sprintf("select %st_item.pk_i_id FROM %st_item %s ORDER BY %st_item.dt_pub_date DESC LIMIT %s", DB_TABLE_PREFIX, DB_TABLE_PREFIX, $prem_where, DB_TABLE_PREFIX, $numItems) . ') AS LIM' );
}
$randSearch->dao->where(DB_TABLE_PREFIX.'t_item.pk_i_id = LIM.pk_i_id');
// group by & order & limit
$randSearch->dao->groupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');
if(!$randomOrder) {
$randSearch->dao->orderBy(DB_TABLE_PREFIX.'t_item.dt_pub_date DESC');
} else {
$randSearch->dao->orderBy('RAND()');
}
$randSearch->dao->limit($numItems);
$rs = $randSearch->dao->get();
if($rs === false){
return array();
}
if( $rs->numRows() == 0 ) {
return array();
}
$items = $rs->result();
return Item::newInstance()->extendData($items);
}
Regards.