Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Featured 'Mini' Links on homepage

(Page 1 of 2)
> >
Quote Reply
Featured 'Mini' Links on homepage
Hi,

I have been reading this thread which gives great information about putting a random number of featured links on the homepage.

However, I need to put 'mini' links on the home page but the globals that people give in the thread I have linked to inserts the whole link based on the content of my link template. Really I need a cut down version of my link template to be displayed as I only want to dispaly photos and titles and not the description. I have yogi's pagebuilder plugin. Can I do something with this to achieve want I am aiming to do or do I need to use a different global?

Alex

www.indigoclothing.com



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
May have found the answer! Would this do the trick?


Code:
my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isFeatured => 'Yes' });
my $output;
for (1 .. 3) {
my $rand = int (rand() * $total);
$link_db->select_options ("LIMIT $rand, 1");
my $sth = $link_db->select ({ isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('mini_link.html', $link);
}
return $output;





Alex

www.indigoclothing.com



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
Yeah, that should work. The decision as to what template to use is decided here (as I'm sure you could guess);

$output .= Links::SiteHTML::display ('mini_link.html', $link);

Its simply a case of you now creating mink_link.html in the admin/templates/default (or whatever set you use), and designing it to suite what you need. If you want, do a <%GT::Template::dump%> call in the mini_link.html template, so you can see what fields you want to use.

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: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
If my recollection is correct, I don't think you want the .html on the end of the template name.

$output .= Links::SiteHTML::display ('mini_link', $link);

Laura.

Edit: Also, noticed some other things

my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isFeatured => 'Yes' ,isValidated=>'Yes'});
my $output;
for (1 .. 3) {
my $rand = int (rand() * $total);
$link_db->select_options ("LIMIT $rand, 1");
my $sth = $link_db->select ({isFeatured=>'Yes', isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('mini_link', $link);
}
return $output;

Last edited by:

afinlr: Jul 2, 2003, 9:31 AM
Quote Reply
Re: [afinlr] Featured 'Mini' Links on homepage In reply to
Thanks for the tips guys - I haven't had time to test this yet but I'll keep you posted!

Regards

Alex

www.indigoclothing.com



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [afinlr] Featured 'Mini' Links on homepage In reply to
>>>If my recollection is correct, I don't think you want the .html on the end of the template name.<<<

Yeah, you are correct. My mistake Blush

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] Featured 'Mini' Links on homepage In reply to
I have been using featured 'mini' links on my hompage for the last few weeks thanks to the the helpful follow ups to my original thread.

The results can be seen at: www.indigoclothing.com

However, duplicate links are called often, more than is statisically possible in fact (keep refreshing the page and you will see what I mean!).

When calling 3 random links, can the global be modified so that the links called are not duplicates?

Many thanks

Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
You could try changing;

my $sth = $link_db->select ({isFeatured=>'Yes', isValidated => 'Yes' });

to

my $sth = $link_db->select ( [ 'DISCTICT(Title)' ],{isFeatured=>'Yes', isValidated => 'Yes' });

Not sure if that is the format... I know that DISTICT can be used to limit the results to unique items. .. as I use it in one of my plugins (not with other 'select' options though, which is why it may not 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] Featured 'Mini' Links on homepage In reply to
Thanks for the prompt reply but I am afraid it does not work - a message comes up saying:

unable to compile 'isFeatured'



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
How about;

my $sth = $link_db->select ( 'DISTINCT(Name)',{isFeatured=>'Yes', isValidated => 'Yes' });

I'm not even sure DISTINCT can be used in conjunction with other SELECT properties (i.e isValidated=> 'Yes')

Unsure

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] Featured 'Mini' Links on homepage In reply to
Nope - Still no luck - Thanks for trying though!

Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
Hi,

Are you saying you are getting two the same link on the display, or that certain links are coming up much more often?

Either way, this has to do with how the random number generator is seeded.

Also, not all versions of MySQL in deployment allow a radom select.

Here is a page that offers some solutions, and brain candy: http://www.webclass.ru/tut.php?tut=198

"SELECT * FROM tablename
WHERE somefield='something'
ORDER BY RAND() LIMIT 5";

Order by RAND() only works in later versions of MySQL.

From the mysql manual:

Quote:


RAND()
RAND(N) Returns a random floating-point value in the range 0 to 1.0. If an integer argument N is specified, it is used as the seed value (producing a repeatable sequence): mysql> SELECT RAND(); -> 0.9233482386203mysql> SELECT RAND(20); -> 0.15888261251047mysql> SELECT RAND(20); -> 0.15888261251047mysql> SELECT RAND(); -> 0.63553050033332mysql> SELECT RAND(); -> 0.70100469486881You can't use a column with RAND() values in an ORDER BY clause, because ORDER BY would evaluate the column multiple times. From version 3.23 you can do: SELECT * FROM table_name ORDER BY RAND() This is useful to get a random sample of a set SELECT * FROM table1,table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000. Note that a RAND() in a WHERE clause will be re-evaluated every time the WHERE is executed. RAND() is not meant to be a perfect random generator, but instead a fast way to generate ad hoc random numbers that will be portable between platforms for the same MySQL version.


From jump.pm, selecting a random number within a range from perl (jump.cgi's random rarely returns the same link)

Code:
# If we are chosing a random link, then get the total and go to one at random.
if (lc $id eq "random") {
my $total = $db->total() - $db->count({ isValidated => 'No' });
my $offset = int rand $total;
$db->select_options ("LIMIT $offset, 1");
my $sth = $db->select ( { isValidated => 'Yes' }, ['ID', 'URL'] );
($id, $goto) = $sth->fetchrow_array;
}


You could use the $offset to return 3 links in a row, by using 3 instead of 1. It would be pseudo random, but so is any random generation of numbers.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Featured 'Mini' Links on homepage In reply to
Thanks Pug dog - I think I understand what you are saying but not quite sure how to implement it - I am a perl newbie Blush!

How would I modify this global to use the $offset to return 3 links:

Code:
my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isFeatured => 'Yes' ,isValidated=>'Yes'});
my $output;
for (1 .. 3) {
my $rand = int (rand() * $total);
$link_db->select_options ("LIMIT $rand, 1");
my $sth = $link_db->select ({isFeatured=>'Yes', isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('mini_link', $link);
}
return $output;



Many Thanks

Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
Sorry to be a pain but I still don't know how to modify my existing global to use the $offset thing that pugdog was talking about. Can any one help? Have had a go myself and am now using:

Code:
sub {
my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isFeatured => 'Yes' ,isValidated=>'Yes'});
my $output;
for (1 .. 3) {
my $offset = int rand $total;
$link_db->select_options ("LIMIT $offset, 1");
my $sth = $link_db->select ({isFeatured=>'Yes', isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('mini_link', $link);
}
return $output;
}

However, the problem still exists as duplicate links (i.e. 2 links out of the 3 shown are the same link) still crop up frequently.

Any clues?


Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery

Last edited by:

IndigoClothing: Aug 30, 2003, 5:39 AM
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
Hi,

Try this:

Code:
sub {
my $link_db = $DB->table('Links');
my $total = $link_db->count ( { isFeatured => 'Yes' ,isValidated=>'Yes'});
my $output;
my $direction = " ASC ";
( int rand (1000) < 500 ) && ($direction = " DESC "); ## fixed
my $offset = int (rand ($total-3)); ## more readable -- we want to grab 3 links at a time.
$link_db->select_options ("ORDER BY ID $direction LIMIT 3 OFFSET $offset"); ## more readable
my $sth = $link_db->select ({isFeatured=>'Yes', isValidated => 'Yes' });
my $link = $sth->fetchrow_hashref;
$output .= Links::SiteHTML::display ('mini_link', $link);
}
return $output;
}


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Aug 31, 2003, 2:40 PM
Quote Reply
Re: [pugdog] Featured 'Mini' Links on homepage In reply to
Quote:
($direction = " DESC ") && ( int rand (1000) < 500 );

This line is assigning DESC to $direction after you've just set it to ASC and then it performs a redundant comparison to see if a random integer below 1000 is lower than 500. I say redundant because it doesn't seem to have any use unless I missed something.

Is that what you intended?
Quote Reply
Re: [Mizuno] Featured 'Mini' Links on homepage In reply to
sorry,

it's supposed to read

( int rand (1000) < 500 ) && ($direction = " DESC ");


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Featured 'Mini' Links on homepage In reply to
Thanks for the reply but the new code comes up with..

"Unable to compile 'isFeatured':"

..when the page is loaded.Frown Is there something wrong with the code?

Thanks for all you help so far. It is very much appreciated.

Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
There looks to be a redundant curly bracket above the "return" line. Also you might need:

require Links::SiteHTML;

....before using the Links::SiteHTML::display line.
Quote Reply
Re: [Mizuno] Featured 'Mini' Links on homepage In reply to
Mizuno,

Thanks for the tips but I am afraid they made no difference as the error still appears.

Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
Could you paste the exact global as it stands.
Quote Reply
Re: [Mizuno] Featured 'Mini' Links on homepage In reply to
On the site at this very moment I am using the exact code as detailed in post#14 as this works but still produces duplicate links which is not good.



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
Hi Alex,

What about this (as Pugdog says above, you'll need mysql 3.23 or above)?

sub {
my $link_db = $DB->table('Links');

$link_db->select_options ("ORDER BY rand()","LIMIT 3");
my $sth = $link_db->select ({isFeatured=>'Yes', isValidated => 'Yes' });
my $output;
while (my $link = $sth->fetchrow_hashref){
$output .= Links::SiteHTML::display ('mini_link', $link);
}
return $output;
}
Quote Reply
Re: [afinlr] Featured 'Mini' Links on homepage In reply to
Thanks for that global:

There are no more duplicates but now one of the links (Lightweight T-shirt) always appears while the other two change fine!

I am not sure which version of mysql I am using - how do I check or do I have to ask my admin?

Alex



Indigo Clothing is a t-shirt printing company based in the UK.
Indigo Clothing | Promotional Clothing | T-Shirt Printing | Embroidery
Quote Reply
Re: [IndigoClothing] Featured 'Mini' Links on homepage In reply to
Hi,

I'm assuming that you are using this global on your live homepage? If so, it seems to be working - at least I'm not getting the lightweight t-shirt on every refresh. I'm not sure how random the rand operator is - it may have just been a statistical blip - like flipping 5 heads in a row.

Laura.
The UK High Street
> >