Random ordering blog section

Your code modifications and patches you want to share with others.
Locked
anthonyo
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Sat Mar 15, 2008 10:38 am

Random ordering blog section

Post by anthonyo » Mon Nov 08, 2010 11:58 am

Hello,

I'd like to have a random ordering option when showing a section blog layout. Thank you very much!

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11403
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Random ordering blog section

Post by ooffick » Mon Nov 08, 2010 12:32 pm

Hi,

you could use the extension MetaMod with the following PHP rule:

Code: Select all

$ret = array();
$ret[] = 34;
$ret[] = 35;
$ret[] = 36;
$ret[] = 37;
shuffle($ret);
return $ret;
Please note that you the number 34 to 37 are just an example and you will need to replace those numbers with the ids of your modules.

Olaf
Olaf Offick - Global Moderator
learnskills.org

anthonyo
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Sat Mar 15, 2008 10:38 am

Re: Random ordering blog section

Post by anthonyo » Mon Nov 08, 2010 12:56 pm

But I'd like a hack from the core component. Let's say I need another ordering option on top of Default, hits... is that possible with the module?

Thank you very much for the quick reply.

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11403
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: Random ordering blog section

Post by ooffick » Mon Nov 08, 2010 1:30 pm

ok, you will need to add the following to the query helper (.../components/com_content/helpers/query.php):

search for this:

Code: Select all

			case 'front' :
				$orderby = 'f.ordering';
				break;
and replace it with this:

Code: Select all

			case 'front' :
				$orderby = 'f.ordering';
				break;
			case 'random' :
				$orderby = 'rand()';
				break;
and then go to the blog.xml file (/..../components/com_content/views/section/tmpl/blog.xml) and use the following:
find this one:

Code: Select all

				<option value="order">Ordering</option>
and replace it with this:

Code: Select all

				<option value="order">Ordering</option>
				<option value="random">RANDOM</option>
Please note this is a hack, and will most likely be overwritten when you update your site to a new Joomla! version.

Olaf
Olaf Offick - Global Moderator
learnskills.org

anthonyo
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Sat Mar 15, 2008 10:38 am

Re: Random ordering blog section

Post by anthonyo » Mon Nov 08, 2010 4:18 pm

Man, you are awesome! It worked as a charm.

Thank you very much, I had another post on extensions with this and it was dead already, I'm sending them to this post. You can say it is SOLVED.


Locked

Return to “Core Hacks and Patches”