Advertisement:

Author Topic: Veronika MB Theme - Exclude listing from a category in mainpage  (Read 298 times)

leuname07

  • Newbie
  • *
  • Posts: 39
Hi guys,

I use  Veronika Theme and i want to exclude the ads from a specific category in homepage. This category is a category for adult.

This the code in Veronika theme for the latest ads :

Code: [Select]
function veronika_random_items($numItems = 10, $category = array(), $withPicture = false) {
  $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($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);
}

Can you help me ! Thank youuu !

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Veronika MB Theme - Exclude listing from a category in mainpage
« Reply #1 on: May 01, 2019, 08:16:13 pm »
Hello,

Try this. You can add your category IDs in $excluded_categories array.

Code: [Select]
<?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->fromDB_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 ) {
    
$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_PREFIXDB_TABLE_PREFIXDB_TABLE_PREFIXDB_TABLE_PREFIXDB_TABLE_PREFIXDB_TABLE_PREFIX$prem_whereDB_TABLE_PREFIXDB_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_PREFIXDB_TABLE_PREFIX$prem_whereDB_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() == ) {
    return array();
  }

  
$items $rs->result();
  return 
Item::newInstance()->extendData($items);
}

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Veronika MB Theme - Exclude listing from a category in mainpage
« Reply #2 on: May 02, 2019, 12:55:35 pm »
Hello,

I have this error :

Parse error: syntax error, unexpected '$whe' (T_VARIABLE) on line 976

the line 976 :
Code: [Select]
      $whe .= ' AND '.DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN ('.$excluded_categories_str.') ';

Thank you !

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Veronika MB Theme - Exclude listing from a category in mainpage
« Reply #3 on: May 02, 2019, 01:04:41 pm »
Missing semicolon on line before.

Code: [Select]
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.') ';
  }

Regards.

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Veronika MB Theme - Exclude listing from a category in mainpage
« Reply #4 on: May 02, 2019, 02:14:39 pm »
Ok. I don't have errors now.

I have put the category 453 but i see the items in mainpage from this category.


leuname07

  • Newbie
  • *
  • Posts: 39
Re: Veronika MB Theme - Exclude listing from a category in mainpage
« Reply #5 on: May 02, 2019, 02:21:42 pm »
You think, i need to put the number of the subcategory too or just the number of the principal category is enough ?

leuname07

  • Newbie
  • *
  • Posts: 39
Re: Veronika MB Theme - Exclude listing from a category in mainpage
« Reply #6 on: May 02, 2019, 03:46:41 pm »
I have test and put the id of the subcategory and it'OK !

THANK YOU !!!!