Closed Arref closed 2 years ago
I am guessing it has something to with this section of code from osclass\oc-includes\osclass\helpers\hItems.php
at line 1067 `/**
@return boolean It returns true if there is another item available or false if there isn't */ function osc_has_latest_items($total_latest_items = null, $options = array(), $withPicture = false) { // if we don't have the latest items loaded, do the query if ( !View::newInstance()->_exists('latestItems') ) { $search = Search::newInstance(); if( !is_numeric($total_latest_items) ) { $total_latest_items = osc_max_latest_items(); }
View::newInstance()->_exportVariableToView('latestItems', $search->getLatestItems($total_latest_items, $options, $withPicture)); }
// keys we want to erase from View $to_erase = array('resources', 'item_category', 'metafields'); foreach($to_erase as $t) { if ( View::newInstance()->_exists($t) ) { View::newInstance()->_erase($t); } }
// set itemLoop to latest if it's the first time we enter here if(View::newInstance()->_get('itemLoop') !== 'latest') { View::newInstance()->_exportVariableToView('oldItem', View::newInstance()->_get('item')); View::newInstance()->_exportVariableToView('itemLoop', 'latest'); }
// get next item $item = View::newInstance()->_next('latestItems');
if(!$item) { View::newInstance()->_exportVariableToView('item', View::newInstance()->_get('oldItem')); View::newInstance()->_exportVariableToView('itemLoop', ''); } else { View::newInstance()->_exportVariableToView('item', View::newInstance()->_current('latestItems')); }
// reset the loop once we finish just in case we want to use it again if( !$item && View::newInstance()->_count('latestItems') > 0 ) { View::newInstance()->_reset('latestItems'); }
return $item; }`
This project is dead, some forks exist, but they aren't actively maintained afaik either. Forum is offline, it had a lot of resources.
Code you can try is this one, put it inside theme's functions.php and replace it in your theme's main view file (exclude cat ID is for your inspiration only):
// random latest items + with images only + exclude specific category ID
function cust_latest_items_random_with_images() {
if (osc_is_home_page()) {
$mSearch = Search::newInstance();
$query_elements = (array) json_decode($mSearch->toJson());
// $excluded_id = 9; // if no permalinks enabled => use category IDs
$mSearch->addJoinTable(count($query_elements['tables_join']), DB_TABLE_PREFIX . 't_item_resource r', DB_TABLE_PREFIX . 't_item.pk_i_id = r.fk_i_item_id', 'LEFT');
$mSearch->addConditions("r.s_content_type LIKE '%%image%%'");
// $mSearch->addConditions(DB_TABLE_PREFIX."t_item.fk_i_category_id <> " . $excluded_id);
$mSearch->order('RAND()', null);
}
}
osc_add_hook('init', 'cust_latest_items_random_with_images');
This is awesome and perfect! Thank you so much! I'll give this a study to see if I can understand how it works.
I also modified the related_listings() function to randomize the Related listings section of the item view page. @dev-101 You are awesome!
I would like to randomize the landing page's Latest Listings. Rather than show the lates listings by date, I would like to randomize the listings. I am told I can do a subquery using rand() I know there is
View::newInstance()->_exportVariableToView( 'listType' , 'latestItems' );
in osclass\oc-content\themes\sigma\functions.php and in osclass\oc-includes\osclass\gui\main.php
But I cannot figure out how to make a random subquery. Can someone help?