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

Newest Links Global

(Page 2 of 2)
> >
Quote Reply
Re: [afinlr] Newest Links Global In reply to
In Reply To:
Do you mean that you have different installations of Links which are each displayed with a different template set? I'm sure that what you are trying to do is easily solvable I'm just being very slow in understanding what it is!


One installation - 3 template sets. This global gets data from the default template set link.html (link1, link2 or whatever). In my case, I need to get data / formatting from template 2 or 3. I have devised a work around for a 2 template set, but it really doesn't resolve the central issue of the global getting data from anything but the default set.
Quote Reply
Re: [afinlr] Newest Links Global In reply to
In Reply To:
Do you mean that you have different installations of Links which are each displayed with a different template set? I'm sure that what you are trying to do is easily solvable I'm just being very slow in understanding what it is!

Only one install, but 3 template sets. Each used for a different category. This global uses data from the default template set. So if Category "Cats" uses its own template set, I want the data on the Home Page from Cats. Not Cats and Dogs.

My point about mySQL was another attempt at a work around . If the column Cats has data, use global, else false and don't use.
Quote Reply
Re: [gatman] Newest Links Global In reply to
OK - that's a bit clearer. At least, my understanding is now that you would like to show new links from a particular category on the homepage? If so, this should work (hopefully!). If you call it new_cat then you should call it with <%new_cat('5')%> if 5 is the number of the main category that you want to show the newest links from.

sub {
my ($all_ids,@list,$output);
my $cat_id = shift;
$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);
while (my $link = $sth->fetchrow_hashref) {
push @list, $link;
}

foreach my $link (@list) {
# You can either hardcode the html here or use a template
my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
$output .= qq~<li><a href="$detailed_url">$link->{'Title'}</a></li>~;
}

return $output;
}
Quote Reply
Re: [afinlr] Newest Links Global In reply to
That's it - good one !

... and the project goes on ....
Quote Reply
Re: [gatman] Newest Links Global In reply to
Here is how I modified it.

Name: <%home_news('5')%> - Same as above but modified with more variables


sub {
# Home Page News and Press Summary
my ($all_ids,@list,$output);
my $cat_id = shift;
$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);
while (my $link = $sth->fetchrow_hashref) {



push @list, $link;
}


foreach my $link (@list) {
# You can either hardcode the html here or use a template
my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
my $added = "$link->{'Add_Date'}";
my $company = "$link->{'Company'}";
my $desc = "$link->{'NewsItem'}";
unless (length $desc <= 70) {
my $short = substr ($desc, 0, 70);
$short =~ s/\s\S+?$//;
$short .= " ...";
$link->{'NewsItem'} = $short;
}
my $news = "$link->{'NewsItem'}";
$output .= qq~<font size=2><dd><b><a href="$detailed_url">$link->{'NewsHeading'}</a></b><small>- $added <br> By: $company <br> $news </dd></small></font>~;
}

return $output;
}
Quote Reply
Re: [gatman] Newest Links Global In reply to
The above works well on the home page, but any suggestions on using this (or the same logic) on the link.html page?

This gives ALL the category link data under category 2. Now I need to narrow the output to just the links of that respective category.

<%if NewsItem%>
<% output just this category and limit to first 50 characters %>
<%endif%>
Quote Reply
Re: [gatman] Newest Links Global In reply to
Close... but?? using this in link.html, the foreach statement is repeating the entries. I am trying to limit the loop to just one pass. (I tried pop but then I only get the first entry). Help?

sub {
my (@list,$detailed_url);
my $tags = shift;
my ($cat_id, $cat_name) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ("ORDER BY $CFG->{build_sort_order_category}");
my $sth = $link_db->select ( { CategoryID => $cat_id });
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
push @list, $link;
}

#foreach my $link (@list) {

my $link = pop(@list);

my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
my $added = "$link->{'Add_Date'}";
my $company = "$link->{'Company'}";
my $desc = "$link->{'NewsItem'}";
unless (length $desc <= 200) {
my $short = substr ($desc, 0, 200);
$short =~ s/\s\S+?$//;
$short .= " ...";
$link->{'NewsItem'} = $short;
}
my $news = "$link->{'NewsItem'}";
$output .= qq~<b><a href="$detailed_url">$link->{'NewsHeading'}</a></b><small>- $added</small> <br> $news <br><small> By: $company </small><br><br>~;
#}

return $output;
}
Quote Reply
Re: [gatman] Newest Links Global In reply to
I'm not following exactly what you are trying to do, but it seems it may be similar to an issue I'm having with a few of the things I'm trying to do.

On the link.html and detailed.html how are you finding what category you are in?

The only way I can see it working, is if each link is only in one category. I'm trying to do something else, and I can't seem to pass the CategoryID into the link.html/detailed.html and have it work. A <%GT::Template::dump%> shows it is always stripped.

Part of this is a "logic" that a "link" (and thus a detailed page) have no "category" since they can arbitrarily belong to any category defined in CatLinks.

But, in order to provide special features, as you are trying to do -- or even use the prev/next spanning properly, the "link" and "detail page" have to know what category they were browsed into from.

Sort of like with add.cgi. If you are in a category, you trigger an automatic add to that category, if you are not, you are asked to browse to one.

It's a fairly simple (trivial) modification to Links code, the problem is that *is* a modification to links code :)

Where you build a link, and a detailed page, you need to check, $IN and see if CategoryID has been passed in. If so, add it to the $link hash. You need to do this anywhere you want to attach a category to a link, and the link may be in more than one category. *THEN* you need to pass in CategoryID. If your links are always in only ONE category, this subtlety doesn't matter. You might be able to do this with a simple plugin, but that seems *really* overkill in the long run.

This might be a good place to use a prefix type flag. link_ would add any passed variables from $in into the $link hash sent to the template parser.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Newest Links Global In reply to
In Reply To:
I'm not following exactly what you are trying to do, <snip>


Seems I get that alot with my questions, Unfortunately I didn't follow yours. Tongue

I am using the following global on the home page (above)
http://www.gossamer-threads.com/...i?post=226603#226603

I am using detailed pages

I am limiting the user to add to specific child/sub categories only one level down from Parent
http://www.gossamer-threads.com/...i?post=227860#227860

I am using user sessions and I am using two templates

I think the above is a PERL array issue.
Quote Reply
Re: [gatman] Newest Links Global In reply to
For a start, try deleting the lines in red (unnecessary code from the original global). If you still have the problem, are all your links only in one category or can they be in more than one?

sub {
my (@list,$detailed_url);
my $tags = shift;
my ($cat_id, $cat_name) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ("ORDER BY $CFG->{build_sort_order_category}");
my $sth = $link_db->select ( { CategoryID => $cat_id });
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
push @list, $link;
}

#foreach my $link (@list) {

my $link = pop(@list);

my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
my $added = "$link->{'Add_Date'}";
my $company = "$link->{'Company'}";
my $desc = "$link->{'NewsItem'}";
unless (length $desc <= 200) {
my $short = substr ($desc, 0, 200);
$short =~ s/\s\S+?$//;
$short .= " ...";
$link->{'NewsItem'} = $short;
}
my $news = "$link->{'NewsItem'}";
$output .= qq~<b><a href="$detailed_url">$link->{'NewsHeading'}</a></b><small>- $added</small> <br> $news <br><small> By: $company </small><br><br>~;
#}

return $output;
}
The UK High Street
Quote Reply
Re: [afinlr] Newest Links Global In reply to
I am still getting duplicates. One Category. Global to be in link.html which is presented in Travel and Sports

Home->Press->Travel
\_Pygmies Invade Hawaii ->Detailed
\_Goats Fly Over London ->Detailed

Home->Press->Sports
\_ England Defeats Canada ->Detailed
\_Mike Tyson KO's Lennox Lewis ->Detailed
Quote Reply
Re: [gatman] Newest Links Global In reply to
Ok, there is still some confusion about what you are trying to do.

I think that the global that you are using, if you use it in the link.html template, will take the id of the current link and give you back a list of all the other links that are in the same category.

This means that for each link it will print out all the other links in the category - this will give you a lot of duplicates!

I have used a similar global on the detail page to show other links in the same category - but this just gives the list once as there is only one link on the detail page.

Exactly what is it that you want to do? Maybe you can do it just by editing the link.html template? Something like:

<%if Name eq 'Travel'%>\_<%Title%> -><a href="<%DetailedURL%>">Detailed</a><%else%>...Regular link template...<%endif%>
Quote Reply
Re: [afinlr] Newest Links Global In reply to
In Reply To:

Exactly what is it that you want to do? Maybe you can do it just by editing the link.html template? Something like:

<%if Name eq 'Travel'%>\_<%Title%> -><a href="<%DetailedURL%>">Detailed</a><%else%>...Regular link template...<%endif%>


Good Point regarding editing just the links output in the page. I have a table field named NewsItems and here is where the lenghty item is. Like the home page, I want this NewsItem displayed, but limited to say 50 characters. This is what the global a couple posts above does.

<%if LinkType eq CompInfoNews%>
<dl>
<dd><a href="<%detailed_url%>"><%NewsHeading%></a><br>
<b>By:</b> <%Company%><br>
<%NewsItem limited to first 50 characters%>

.. etc..

I dont' see any syntax for limiting the variable in the tag in this way

I was trying to get the above global to stop the duplicates.
Quote Reply
Re: [gatman] Newest Links Global In reply to
To do that you just need a simple global which takes the NewsItem tag, shortens it if necessary and returns the result. Its all there is the global above - you just need to remove all the bits you don't need!

Something like this:

sub {
my $tags = shift;
my $desc = $tags->{'NewsItem'};
unless (length $desc <= 200) {
my $short = substr ($desc, 0, 200);
$short =~ s/\s\S+?$//;
$short .= " ...";
$tags->{'NewsItem'} = $short;
}
my $output = $tags->{'NewsItem'};
return $output;
}
Quote Reply
Re: [afinlr] Newest Links Global In reply to
Code:
sub {
my $tags = shift;
my $desc = $tags->{'NewsItem'};
unless (length $desc <= 200) {
my $short = substr ($desc, 0, 200);
$short =~ s/\s\S+?$//;
$short .= " ...";
$tags->{'NewsItem'} = $short;
}
my $output = $tags->{'NewsItem'};
return $output;
}

You can make that a one liner :)

Code:
sub {
return length($_[0]->{NewsItem}) > 200 ? (substr($desc, 0, 200) . '...') : $_[0]->{NewsItem};
}

I'm not clear on why you added this:

$short =~ s/\s\S+?$//;

Last edited by:

Paul: Jan 11, 2003, 9:29 AM
Quote Reply
Re: [Paul] Newest Links Global In reply to
Yes, I realise it wasn't very elegant - I was just pointing out that everything needed was in the original global.
Quote Reply
Re: [afinlr] Newest Links Global In reply to
Understood. Does the trick!

Many Thanks.
Quote Reply
Re: [gatman] Newest Links Global In reply to
How do I change the detailed url to the jump.cgi for the link
the global has this

my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";

I do not have the detiled pages enabled so I want to change it to the category url or use the jump.cgi url
Quote Reply
Re: [Abusaki] Newest Links Global In reply to
my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";

try

my $detailed_url = "$CFG->{'db_cgi_url'}/jump.cgi?ID=$link->{'LinkID'}";


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Newest Links Global In reply to
Thanks Pupdog, worked really great

in this part
Quote:
foreach my $link (@list) {
# You can either hardcode the html here or use a template
my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
my $added = "$link->{'Add_Date'}";
my $company = "$link->{'Company'}";
my $desc = "$link->{'NewsItem'}";
unless (length $desc <= 70) {
my $short = substr ($desc, 0, 70);
$short =~ s/\s\S+?$//;
$short .= " ...";
$link->{'NewsItem'} = $short;
}
my $news = "$link->{'NewsItem'}";
$output .= qq~<font size=2><dd><b><a href="$detailed_url">$link->{'NewsHeading'}</a></b><small>- $added <br> By: $company <br> $news </dd></small></font>~;
}

return $output;

but how do I use conditions here like

<%if company%> <%company%> <%else%> No Company Name supplied <%endif%>

in the output
Quote Reply
Re: [Abusaki] Newest Links Global In reply to
Hi,

You'd need an "if" statement. Something like;

Code:
if ($link->{company}) {
$output .= qq~<font size=2><dd><b><a href="$detailed_url">$link->{'NewsHeading'}</a></b><small>- $added <br> By: $company <br> $news </dd></small></font>~;
} else {
$output .= qq~<font size=2><dd><b><a href="$detailed_url">$link->{'NewsHeading'}</a></b><small>- $added <br> By: No Company Name supplied <br> $news </dd></small></font>~;
}

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] Newest Links Global In reply to
I used it but only one links shows even thouogh I had the limit set to 3
Quote Reply
Re: [Abusaki] Newest Links Global In reply to
Mmm.. whats the whole global your using now?

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!
> >