Support Forums - Classified Ads Script Osclass
Osclass theme support => Zara Osclass Responsive Theme => Topic started by: jcarrolo01 on September 21, 2019, 06:44:27 PM
-
I have a question regarding programming using "continue" statement...
In my site i'm using zara theme, and i'm building a plugin to avoid display listings from selected categories beign displayed in latest listings... Everithing is working but i have some problems filtering the latest listings... So i came here asking for some help and hope maybe you can found a easy solution for this, and maybe you can help....
The code is this.
<?php View::newInstance()->_exportVariableToView('latestItems', zara_random_items()); ?>
<?php if( osc_count_latest_items() > 0) { ?>
<div class="block">
<div class="wrap">
<?php $c = 1; ?>
<?php while( osc_has_latest_items() ) { ?>
<?php if(osc_is_this_category('skip_latest', osc_item_category_id())) { ?>
<?php continue; ?>
<?php } ?>
<?php zara_draw_item($c, 'gallery'); ?>
<?php $c++; ?>
<?php } ?>
I set in administration to display in latest listings 30 listings and that value comes in function: osc_count_latest_items() with value = 30
I build a plugin to skip listings from selected categorie to be displayed in latest listings section...
The problem is if i have for example 4 listings in a selected category to exclude be displayed in latest listings, im entering 4 times inside the below code and the continue statement send me again for the "while":
<?php if(osc_is_this_category('skip_latest', osc_item_category_id())) { ?>
<?php continue; ?>
<?php } ?>
The final result, and my issue is instead have 30 listings in latest listings i only have 26, because i enter 4 times in the loop with "continue" statement inside...
So the question is, how can i solve this????
Best Regards
-
@jcarolo
You cannot solve your issue in that way, you must find function zara_random_items in functions.php and add condition there that oc_t_item.fk_i_category_id <> your_cats ... so resultset you get has 30 items after filters applied.
-
Thanks allot for your tip...
I analyse the function and its complex.. i will try to do something with your tip...
Anyway, one more time, thanks allot..
Best regards
-
@jcarrolo01
Welcome
-
I think you are talking, and the solution is located in this lines inside zara_random_items function
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.') ';
}
so i just change to:
$listCategories = implode(', ', $subcat_id);
$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id IN ('.$listCategories.') AND ';
$whe .= ' AND '.DB_TABLE_PREFIX.'t_item.fk_i_category_id <> array(Cat1,Cat2,Cat3) ';
Correct??? Or I'm completely wrong???? :) :) :)
Best Regards
-
Something like:
$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id IN ('.$listCategories.') AND ';
$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id not in (1,2,3,4,5) AND ';
-
Finaly i found the solution...
In function zara_random_items
Find:
// 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 ';
Change to:
$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 ';
<b>$whe .= DB_TABLE_PREFIX.'t_item.fk_i_category_id NOT IN (140, 421, 611, 612, 613, 614, 422, 615, 618, 619, 620, 423, 621, 617, 616, 424, 622, 623, 624, 625, 425, 626, 627, 628, 608, 629, 630, 609, 631, 632, 633, 634, 610, 635, 637, 638, 636, 639, 640, 641, 642, 426) AND ';</b>
This work as expected....
Thanks allot for your tips
Best Regards