Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

[ NEW PLUGIN ] Build_Random v1

Quote Reply
[ NEW PLUGIN ] Build_Random v1
I've been looking for a good way to build listings randomly each build (whilst keeping the consistancy, and not having duplicates show up), and I've finally found one out :)

This plugin will populate the new "RandomID" field with a random number (changed each build). You can then change your sort_build_order (please see the documentation with the plugin) so that it orders by the RandomID field too.

This helps you keep consistancy on spanning pages; whilst still being able to have them randomly ordered :)

Details can be found here: http://www.ultranerds.com/...bin/details/117.html

Enjoy! Angelic

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Hi Andy,

Good idea. I was just thinking that you could create a separate script that generates the randomID which could be run via a cron job for dynamic sites? If you've got some spare time Tongue

Laura.
Quote Reply
Re: [afinlr] [ NEW PLUGIN ] Build_Random v1 In reply to
Quote:
I was just thinking that you could create a separate script that generates the randomID which could be run via a cron job for dynamic sites? If you've got some spare time

I guess so :) I'll have a look into it (when I find some time Tongue).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Will this preserve any Priority Links and such?

Priority
New
Random

Thanks Smile

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

Last edited by:

DogTags: Jul 15, 2004, 10:36 AM
Quote Reply
Re: [DogTags] [ NEW PLUGIN ] Build_Random v1 In reply to
DogTags - Yup Cool You manually change the build order to how you want. Its fully reversable too, if you decide not to use it.

Laura -

This should do the trick;

Code:
#!/usr/bin/perl

use strict;
use lib '/path/to/admin';
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/$CFG $IN $DB/;
use LWP::Simple;
use Links::Plugins;

# Inherit from base class for debug and error methods
@Plugins::DMOZ_Wizard::ISA = qw(GT::Base);

# print a "Done" message
print "\nStarting RandomID Generation...";

# run the update...
$DB->table('Links')->update( { RandomID => \"RAND() * 15" } )
|| die $GT::SQL::error;


# print a "Done" message
print "\nDone...";

Just put it in a script called update_random.cgi, and then set it to run via cron with something like;

Code:
0 0 * * * /usr/bin/perl /full/path/to/admin/update_random.cgi

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Thanks, And. That's great Cool

Cheerio Smile

------------------------------------------
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Smile Thanks.
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Does this mean a listing on span page 2 could end up on page 1 after a build?

Interesting plugin Andy.

--------------------------------
Privacy Software
Quote Reply
Re: [BLOOD] [ NEW PLUGIN ] Build_Random v1 In reply to
Quote:
Does this mean a listing on span page 2 could end up on page 1 after a build?

Yup :) It just gives them a build order ID number, and LSQL should then follow that pretty well :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Hi Andy

Hey does this plugin still keep Paid links above free ones?

Do I need to do anything special to make that happen, or will it do that by default.

Thanks!

Regan.
Quote Reply
Re: [ryel01] [ NEW PLUGIN ] Build_Random v1 In reply to
Hi. All it does it make a random number each time the build process is run. Its up to you (so you can decide on what effect it will have with a build). For example, you could use;

Code:
RandID DESC, isNew DESC, isPop DESC, Title DESC

..or if you want new links to show up first;

Code:
isNew DESC, RandID DESC, isPop DESC, Title DESC

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
hi andy

yip - got that, but after you enter the random number into the sort order, does it still keep the paid links above the free links - or doesn't it affect that at all?

ie... will it still display the paid links first but in random order like...

random paid link2
random paid link1
random paid link4
random paid link3

random free link1
random free link3
random free link5
random free link4

hope that makes sense. Crazy

regan
Quote Reply
Re: [ryel01] [ NEW PLUGIN ] Build_Random v1 In reply to
It all depends on how you setup your build_category_sort_order. I'm not quite sure on your sort order at the moment. If you could paste it here, then I'll have a look.. and let you know if it should work :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
hi Andy

At the moment it is just...

Code:
Name

but the paid links still get displayed first. So the question is, will the paid links still be displayed first (but random paid, then random free) if I have this instead...

Code:
RandomID Name

I think they will thinking about it because no matter what I put there using the normal fields it still displays the paid links first, so the random one is just another field.

I think i just answered it myself.

r
Quote Reply
Re: [ryel01] [ NEW PLUGIN ] Build_Random v1 In reply to
Quote:
I think i just answered it myself.

LOL!

I guess the best way to find out, is to give it go :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
too many late nights getting ready for an upgrade... Pirate

thanks

r
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Andy,

Would it be possible to set the random number field only when another field matches a certain value?

For example, I'd like paid links to be be listed first, in random order, but all the remaining listings shown in alphabetical order.

Paid_Listing DESC,RandomID DESC,Title ASC


-Theo
Quote Reply
Re: [theo@itools] [ NEW PLUGIN ] Build_Random v1 In reply to
Sure thing. It runs off a field called Rand (I think <G>), which is randomly populated with each build. This can then be used as sort order option, i.e;

isNew DESC, isPop DESC, Rand, Title DESC ..etc

Quite a simple plugin to use Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Thanks for the quick reply, Andy. Either I don't quite understand your answer, or you didn't quite understand my question. Wink

I actually want any Paid links listed first (and randomly), and the free links listed next (and alphabetically). How do I get the plugin to populate "Rand" only in the Paid links?
Quote Reply
Re: [theo@itools] [ NEW PLUGIN ] Build_Random v1 In reply to
Mmm... not actually sure. Problem is, trying to work out which links are paid (havn't really played with that too much). I **think** you can use isPaid in the templates, but I'm not sure its an actual field (i.e so you can't order by it). I could be totally wrong though :D

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
I was actually planning on using a new, custom field rather than isPaid.
Quote Reply
Re: [theo@itools] [ NEW PLUGIN ] Build_Random v1 In reply to
Well, in that case it should be totally possible :)

Something like;

isPaid DESC, Rand, Title DESC

Should hopefully work :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
Andy,

Just a note - I found that if you use RAND(CURDATE()) it will order the links randomly using the current date as a seed - so that you get a consistent ordering for that day and it changes for the next day (for dynamic sites). This should also work for static sites (as long as you don't build over midnight).

Laura.
Quote Reply
Re: [Andy] [ NEW PLUGIN ] Build_Random v1 In reply to
In Reply To:

isPaid DESC, Rand, Title DESC
p


But since all links get the "Rand" field, the non-paid links are sorted randomly. I'd to find some way to tweak the Plugin so that the Rand field is removed (or set as zero) for the non-sponsored links, or alternatively a way to sort based on an if statement - if Sponsored > 0, sort on Rand DESC.

Last edited by:

Andy: Apr 6, 2005, 11:38 PM