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

Latest links on home page

Quote Reply
Latest links on home page
Hi there,

I am setting up a global to display links on the home page. I found this in the forum which works great EXCEPT I am using detailed pages for some of my links and this global does not recognise this tag (Unknown Tag: 'detailed_url')

what do I need to add/change to do this? FYI... I am fairly new to this so I do not fully understand whats going on in the sub...

Sub: latest_links

sub {
my ($cat_id,$all_ids,@list,$output,$link_db,$condition);
$cat_id = shift;
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
$link_db = $DB->table('Links','CatLinks','Category');
$link_db->select_options ("ORDER BY Add_Date DESC LIMIT 5");
$condition = GT::SQL::Condition->new( 'isValidated','=','Yes','isNew','=','Yes','CategoryID', 'IN', \@$all_ids);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link_homenew', $link);
}
return $output;
}

Called on page using: <%latest_links('76')%>

76 - is the category to show new links from

Many thanks
Quote Reply
Re: [aquaman] Latest links on home page In reply to
Here is the code I am using in the template:

<li><%if detailed_url and isValidated eq 'Yes'%><a href="<%detailed_url%>"><%elsif URL ne 'http://' and isValidated eq 'Yes'%><a href="<%escape_html URL%>"><%Title%></a><%endif%></li>

doesnt pickup the detailed url. Is this something that needs to be setup as a global and then dropped into the above code?

Thanks
Quote Reply
Re: [aquaman] Latest links on home page In reply to
You need to add the detailed_url into the global. Here's an example:
http://www.gossamer-threads.com/...i?post=273665#273665
Quote Reply
Re: [aquaman] Latest links on home page In reply to
Try this code:
Code:
sub {
my $cat_id = shift;
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $link_db = $DB->table('Links','CatLinks','Category');
$link_db->select_options ("ORDER BY Add_Date DESC LIMIT 5");
my $condition = GT::SQL::Condition->new(
'isValidated','=','Yes',
'isNew','=','Yes',
'CategoryID', 'IN', \@$all_ids
);
my $sth = $link_db->select($condition);
my $output;
while (my $link = $sth->fetchrow_hashref) {
$link->{detailed_url} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('link_homenew', $link);
}
return $output;
}

Just added the detailed_url tag, and did some code style changes.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [aquaman] Latest links on home page In reply to
Global task: Display the Last X new links.
Global code:
Code:
sub {
# Displays the Last X new links.
my $new_nr = shift;
my $search_db = $DB->table('Links');
$search_db->select_options ("ORDER BY Add_Date DESC Limit $new_nr");
my $sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
my $output;
while (my $link = $sth->fetchrow_hashref) {
$link->{'category_url'} = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}


Global Usage:
<%new_links('10')%>

10 = number of new links to be displayed


I also posted the code to Links SQL/Globals resources page.

It would be good idea to have more & more globals posted into the resource page above.
If you see any useful globals on the forum, please post them to the resource page listed above.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Latest links on home page In reply to
This is such a good global by webmaster33 , it’s the only one I have found that returns the correct url's when using the StaticURLtr plugin!

The only change I think would be even better is to covert this into a loop global - thus allowing more flexibility.

Can be done with only a few changes?

--------------------------------
Privacy Software

Last edited by:

BLOOD: Jan 10, 2006, 2:46 AM
Quote Reply
Re: [webmaster33] Latest links on home page In reply to
We should use 'VIEWABLE' instead of isValidated => 'Yes'

http://www.gossamer-threads.com/...ing=VIEWABLE;#266223
Quote Reply
Re: [Payooo] Latest links on home page In reply to
Thanks for the info!

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [BLOOD] Latest links on home page In reply to
I don't really understand how would you want to make it a "loop global".
This global simply takes the last X of the database query.

How would you want to use in a loop?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Latest links on home page In reply to
Its ok, not needed now - thanks.

--------------------------------
Privacy Software