*

webcity

  • ****
  • 234 posts
Re: Premium listings in Random Order
« Reply #15 on: September 26, 2022, 05:22:47 PM »
You can make them scroll back and reverse on home using script
in style.css / underneath line:  /* ITEM GRID & LIST */ 
Code: [Select]
.products.q1 { display: flex; flex-wrap: nowrap; flex-direction: row; overflow-x: scroll; }

File main.php search for
Code: [Select]
<div id="premium-items" class="products grid nice-scroll no-visible-scroll">
And replace with:
Code: [Select]
<div id="q1" class="products grid nice-scroll q1 no-visible-scroll">

In same section after first </div> put
Code: [Select]
      <script>
function animatethis(targetElement, speed) {
    var scrollWidth = $(targetElement).get(0).scrollWidth;
    var clientWidth = $(targetElement).get(0).clientWidth;
    $(targetElement).animate({ scrollLeft: scrollWidth - clientWidth },
    {
        duration: speed,
        complete: function () {
            targetElement.animate({ scrollLeft: 0 },
            {
                duration: speed,
                complete: function () {
                    animatethis(targetElement, speed);
                }
            });
        }
    });
};
animatethis($('#q1'), 80000);
</script>

Thanks for you suggestion and help :-)

I would prefer to show random ads though, as having too many hidden ads on the page will effect the page loading times.

Thanks again for your help

*

MB Themes

Re: Premium listings in Random Order
« Reply #16 on: September 27, 2022, 06:28:31 PM »
Until you use lazy load, it should be fine.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 473 posts
Re: Premium listings in Random Order
« Reply #17 on: September 26, 2024, 04:45:24 PM »
After a long period, I’m posting the solution to display premium items in random order for those who did not have a solution for this yet. In file main.php look for:
Code: [Select]
<?php View::newInstance()->_exportVariableToView('items'$default_items); ?>
Beneath that line, change code up to line:
Code: [Select]
<?php osc_run_hook('home_premium'); ?>

Copy / paste code:
Code: [Select]
<?php 
    $has_day_offer 
0;
    if(
eps_param('enable_day_offer') == && eps_param('day_offer_id') > 0) {
        
$day_offer Item::newInstance()->findByPrimaryKey(eps_param('day_offer_id'));
        
        if(
$day_offer !== false && isset($day_offer['pk_i_id'])) {
            
$has_day_offer 1;
        }
    }

    
// Fetch premium items
    
$premium_items eps_premium_items(eps_param('premium_home_count') - $has_day_offer, @$day_offer['pk_i_id']);

    
// Shuffle premium items for random order on each page load
    
if($premium_items) {
        
shuffle($premium_items);

        
// Apply admin setting for the number of items to display
        
$premium_item_count eps_param('premium_home_count') - $has_day_offer;
        
$premium_items array_slice($premium_items0$premium_item_count);
    }
?>


<?php if(eps_param('premium_home') == && count($premium_items) > 0) { ?>
    <?php
        $default_items 
View::newInstance()->_get('items'); 
        
View::newInstance()->_exportVariableToView('items'$premium_items);
    
?>

<section class="home-premium">
  <div class="container">
    <div class="block">
      <h2><?php _e('Today\'s premium selection''epsilon'); ?></h2>

      <div class="nice-scroll-wrap">
        <div class="nice-scroll-prev"><i class="fas fa-caret-left"></i></div>
        <div id="premium-items" class="products grid nice-scroll no-visible-scroll">
          <?php 
            $c 
1

            
// Add the day offer first, if present
            
if($has_day_offer == 1) {
                
View::newInstance()->_exportVariableToView('item'$day_offer);
                
eps_draw_item($cfalseeps_param('premium_home_design'));
                
$c++;
            }

            
// Add the shuffled and limited premium items
            
while(osc_has_items()) {
                
eps_draw_item($cfalseeps_param('premium_home_design'));
                
$c++;
            }
          
?>

        </div>
        <div class="nice-scroll-next"><i class="fas fa-caret-right"></i></div>
      </div>
    </div>
  </div>
</section>

<?php View::newInstance()->_exportVariableToView('items'$default_items); ?>
<?php ?>



For those that want to use auto scroll left to right on premiums with random shuffle use code:

Code: [Select]
<?php 
    $has_day_offer 
0;
    if(
eps_param('enable_day_offer') == && eps_param('day_offer_id') > 0) {
      
$day_offer Item::newInstance()->findByPrimaryKey(eps_param('day_offer_id'));
      
      if(
$day_offer !== false && isset($day_offer['pk_i_id'])) {
        
$has_day_offer 1;
      }
    }

    
// Fetch premium items
    
$premium_items eps_premium_items(eps_param('premium_home_count') - $has_day_offer, @$day_offer['pk_i_id']);

    
// Shuffle premium items for random order on each page load
    
if($premium_items) {
      
shuffle($premium_items);

      
// Apply admin setting for the number of items to display
      
$premium_item_count eps_param('premium_home_count') - $has_day_offer;
      
$premium_items array_slice($premium_items0$premium_item_count);
    }
?>


<?php if(eps_param('premium_home') == && count($premium_items) > 0) { ?>
    <?php
      $default_items 
View::newInstance()->_get('items'); 
      
View::newInstance()->_exportVariableToView('items'$premium_items);
    
?>

<section class="home-premium">
  <div class="container">
    <div class="block">
      <h2><?php _e('Today\'s premium selection''epsilon'); ?></h2>

      <div class="nice-scroll-wrap">
        <div id="premium-items" class="products grid nice-scroll no-visible-scroll">
          <?php 
            $c 
1

            
// Add the day offer first, if present
            
if($has_day_offer == 1) {
              
View::newInstance()->_exportVariableToView('item'$day_offer);
              
eps_draw_item($cfalseeps_param('premium_home_design'));
              
$c++;
            }

            
// Add the shuffled and limited premium items
            
while(osc_has_items()) {
              
eps_draw_item($cfalseeps_param('premium_home_design'));
              
$c++;
            }
          
?>

        </div>
      </div>
    </div>
  </div>
</section>

<?php View::newInstance()->_exportVariableToView('items'$default_items); ?>
<?php ?>

<script>
document.addEventListener("DOMContentLoaded", function() {
  var premiumItems = document.getElementById('premium-items');
  var scrollAmount = 1; // Adjust the scroll speed as desired
  var scrollDirection = 1; // 1 for right, -1 for left
  var scrollInterval = 30; // Time interval for scrolling, can be adjusted
  var autoScrollTimeout;

  function autoScroll() {
    if (premiumItems) {
      premiumItems.scrollLeft += scrollAmount * scrollDirection;

      // If we reach the right side, change direction to left
      if (premiumItems.scrollLeft + premiumItems.clientWidth >= premiumItems.scrollWidth) {
        scrollDirection = -1;
      }

      // If we reach the left side, change direction to right
      if (premiumItems.scrollLeft <= 0) {
        scrollDirection = 1;
      }

      // Call this function again to continue scrolling
      autoScrollTimeout = setTimeout(autoScroll, scrollInterval);
    }
  }

  // Start the automatic scroll with a small delay to ensure the content is fully loaded
  setTimeout(autoScroll, 100);

  // Stop scrolling on mouseover
  premiumItems.addEventListener('mouseover', function() {
    clearTimeout(autoScrollTimeout);
  });

  // Restart scrolling on mouseout
  premiumItems.addEventListener('mouseout', function() {
    autoScroll();
  });
});
</script>

<?php osc_run_hook('home_premium'); ?>

Cheers :P
« Last Edit: September 26, 2024, 07:14:09 PM by mwindey »