97 Posts
Anjo
10 years ago
Topic

Hi

Wondering if anyone has a solution.

I am using tpl_basic_list template to show my listings and I use ‘shuffle’ code to shuffle the listings.

In admin I have ordering based on rank system (ascending) using a select-simple field with 1 and 2 as options. I would like to shuffle the items but maintain the ranking order so that rank 1 always above 2 but still shuffles.

Thanks

Anjo

Get a VIP membership
693 Posts
rpoy
10 years ago
0
Level 1

Hi Anjo,

It appears that any order that SEBLOD creates in the $items list has been overwritten by the shuffle function.  You would need to write your own shuffle function, or you can contact Octopoos if you need assistance with that.

regards,

Randy

97 Posts
Anjo
10 years ago
0
Level 1

I managed to solve this with a little help from a friend see code below. The reason why I needed this feature is so that I can place paid listings in my directory in order according to ranking (how much client paid for listing) while still shuffling the listings so that there is no preference who comes top from their respective rank . I have three types of listing Premium, Enhanced and Free and Premium always needs to be above Enhanced which needs to be above Free.

This is for tpl_basic_list template by jasongallagher. I created a rank field using select simple with 3 options 1 – Premium, 2 – Enhanced, 3 – Free. Then placed the rank field in the ordering tab (Ascending) and in the list tab in the backend. Then the following code in template:

-----------------------------------------------------------------------------

<?php

$items = $cck->getItems();

shuffle($items); //Shuffles the all the entries

$premium = array(); //create new array for premium

$enhanced = array(); //create new array for enhanced

$free = array(); //create new array for free

foreach( $items as $item ) {

if($item->getValue('rank') == 1) {

array_push($premium, $item);

}

else if($item->getValue('rank') == 2){

array_push($enhanced, $item);

}

else if($item->getValue('rank') == 3){

array_push($free, $item);

}

$items = array_merge($premium, $enhanced, $free); //MERGES ARRAYS IN ORDER

}

foreach( $items as $item ) {

$count++;

?>

---------------------------------------------------------------------------------------------------------

Another useful feature I have is the ability to place adverts in between listings by inserting a joomla image module after this code

----------------------------------------------

<?php if ($count == 1 ) : ?>

<?php elseif ($count == 3) :?>

Which after the first two listings it places the module. If you want to add more:

<?php elseif ($count == 7) : ?>

--call module

--------------------------------------------------------------------------------------------------

HERE IS THE FULL CODE FOR THE TEMPLATE INDEX.PHP FILE

<?php /** * blank template by Jason Gallagher: www.jasongallagher.org * @copyrightCopyright (C) 2012 Jason Gallagher. All Rights Reserved. **/ // No Direct Access defined( '_JEXEC' ) or die; ?> 

<?php require_once dirname(__FILE__).'/config.php'; $cck=CCK_Rendering::getInstance(); if ( $cck->init() === false ) { return; } $document =& JFactory::getDocument(); $document->addStyleSheet(JURI::base().'templates/'. $this->template. "/css/list.css"); ?> 

<?php $items = $cck->getItems(); 

shuffle($items); //Shuffles the all the entries 

$premium = array(); //create new array for premium 

$enhanced = array(); //create new array for enhanced 

$free = array(); //create new array for free 

foreach( $items as $item ) { 

if($item->getValue('rank') == 1) { 

array_push($premium, $item); } 

else if($item->getValue('rank') == 2){ 

array_push($enhanced, $item); } 

else if($item->getValue('rank') == 3){ 

array_push($free, $item); } 

$items = array_merge($premium, $enhanced, $free); //MERGES ARRAYS IN ORDER 

foreach( $items as $item ) { 

$count++; ?> 

<!-- IMPORTANT call your fields like $item->get('the_field')->value INSTEAD OF $cck->get('the_field')->value --> 

<!-- CALL ALL THE LISTING FIELDS HERE --> 

<?php echo $item->renderField('art_title'); ?> 

<!-- INSERT JOOMLA MODULE HERE --> 

<?php if ($count == 1 ) : ?> 

<?php elseif ($count == 3) :?> 

<?php echo $item->renderField('advert_p1'); ?><!-- JOOMLA MODULE FOR EXAMPLE RANDOM IMAGE --> 

<?php elseif ($count == 7) : ?> <!-- CALL MODULE ON THE 7TH ENTRY --> 

<?php elseif ($count == 11) : ?> <!-- CALL MODULE ON THE 11TH ENTRY --> 

<?php endif;$count++; ?> 

<?php } ?> <?php $cck->finalize(); ?>

Get a VIP membership