Gossamer Forum
Home : Products : Gossamer Links : Discussions :

can I limit the characters on the link page?

Quote Reply
can I limit the characters on the link page?
Maybe Im blind in this matter but it seems to me silly to have a detailed page if it says the same thing as the links page.

How about limiting the amount of characters to the first say 100, then putting a "more" link that will take them to the detailed page with the full details of what the link is about?

Is this already in Glinks 3.0.4 or is it a wish list item?
Quote Reply
Re: [aph] can I limit the characters on the link page? In reply to
Hi,

Theres a ton of globals for this =)

Here's one I slightly modified for you, to give a bit more flexability;

Code:
sub {

# Displays the Description Short and formatted with line breaks.

my $value = $_[0];
my $length= $_[1] || 75;

my $Description = $value;

$Description = GT::CGI::html_escape($Description);

$Description =~ s/\n/<br \/>\n/g;
$Description =~ s,\[(/?i)\],<$1>,g;
$Description =~ s,\[(/?b)\],<$1>,g;
length $Description < $length and return $Description;
my $short = substr ($Description, 0, $length);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;

}

Call with:

<%global_name($Description,100)%>

..which would get the first 100 charachters from the <%Description%> field.

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] can I limit the characters on the link page? In reply to
Wow, this one also supports some simple BBCodes, too Cool

It also replaces \[ b \] and \[ i \] codes to html ones, having bold and italic support.

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] can I limit the characters on the link page? In reply to
Cool

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] can I limit the characters on the link page? In reply to
I really do apologize but your talking to someone that hasn't modified links since links sql first came out, so I have no idea where all of this goes.

Again my apologies, perhaps you or someone can tell me where it would go using the luna template pack?

Thank you for your time Andy.


In Reply To:
Hi,

Theres a ton of globals for this =)

Here's one I slightly modified for you, to give a bit more flexability;

Code:
sub {

# Displays the Description Short and formatted with line breaks.

my $value = $_[0];
my $length= $_[1] || 75;

my $Description = $value;

$Description = GT::CGI::html_escape($Description);

$Description =~ s/\n/<br \/>\n/g;
$Description =~ s,\[(/?i)\],<$1>,g;
$Description =~ s,\[(/?b)\],<$1>,g;
length $Description < $length and return $Description;
my $short = substr ($Description, 0, $length);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;

}

Call with:

<%global_name($Description,100)%>

..which would get the first 100 charachters from the <%Description%> field.

Hope that helps =)

Cheers
Quote Reply
Re: [aph] can I limit the characters on the link page? In reply to
Hi,

No problem =) Heres a step-by-step guide;

1) Copy the following;

Code:
sub {

# Displays the Description Short and formatted with line breaks.

my $value = $_[0];
my $length= $_[1] || 75;

my $Description = $value;

$Description = GT::CGI::html_escape($Description);

$Description =~ s/\n/<br \/>\n/g;
$Description =~ s,\[(/?i)\],<$1>,g;
$Description =~ s,\[(/?b)\],<$1>,g;
length $Description < $length and return $Description;
my $short = substr ($Description, 0, $length);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;

}

2) In your admin panel, goto Build > Template Globals.

Go to the bottom of the page, and look for the "empty" box.

Type;

Name: shorten_field
Value: (the code from above, EXACTLY as its shown)

3) In link.html, change references of <%Description%> to <%shorten_field($Description,100)%>

4) You shouldn't need to make any changes in detailed.html.

Hope that helps 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] can I limit the characters on the link page? In reply to
Okay I've done what you said to the letter, I've made a template global and inserted it iexactly through copy and paste, even pasted it ino notepad so that the formatting would be correct, then pasted from there to the template global named shorten_field, here is what is in it now:
Code:

sub {

# Displays the Description Short and formatted with line breaks.

my $value = $_[0];
my $length= $_[1] || 75;
my $Description = $value;
$Description = GT::CGI::html_escape($Description);
$Description =~ s/\n/<br \/>\n/g;
$Description =~ s,\[(/?i)\],<$1>,g;
$Description =~ s,\[(/?b)\],<$1>,g;
length $Description < $length and return $Description;
my $short = substr ($Description, 0, $length);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;
}

And in my link template I only found one <%Description%> tag so I replaced it, it now says:

Code:

<%if Description%><div class="linkdescription"><%if highlight%><%Links::Tools::highlight($Description, $query)%><%else%<%shorten_field($Description,100)%><%endif%></div><%endif%>

Now what shows up is the standard tan box that looks like it could hold 100 characters, but no description text at all, I go to the detail page and there is a description well over 100 characters.

Any clues?
Quote Reply
Re: [aph] can I limit the characters on the link page? In reply to
Hi,

You're missing a > Tongue

Try this;

Code:
<%set DescriptionNew = shorten_field($Description,100)%>

<%if Description%><div class="linkdescription"><%if highlight%><%Links::Tools::highlight($DescriptionNew,$query)%><%else%><%DescriptionNew%><%endif%></div><%endif%>

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] can I limit the characters on the link page? In reply to
Yup was the missin > I put that back in and it works really nice, what is the new code? <%set DescriptionNew = shorten_field($Description,100)%> and should I just put it one line above the one that was missing the > What does it do?
Quote Reply
Re: [aph] can I limit the characters on the link page? In reply to
Hi,

Great :)

Quote:
hat is the new code? <%set DescriptionNew = shorten_field($Description,100)%> and should I just put it one line above the one that was missing the > What does it do?

Its to take into account the <%if highlight%><%Links::Tools::highlight($DescriptionNew,$query)%> <%endif%> part, which wouldn't get passed through the global otherwise (thus you will end up with the normal length descriptions, if "highlight" is turned on it searches).

NB, if you're going to add that.. you need to be sure to change instances of "Description" to "DescriptionNew", or it'll just show blank values =)

Theres a logic behind it =)

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] can I limit the characters on the link page? In reply to
Andy

this is a great 'Global'

I've tried this on my new site, although I have a problem with some of the 'descriptions' as they are 'affiliate' links that uses <script language="JavaScript" to display 'editorial' text from the affliate site.

These 'affiliate' link descriptions are not displaying very well!

Any suggestions or could you modify the code to not shorten the affiliate link descriptions that use <script language="JavaScript"

Any help appreciated.

Thanks
Colin Thompson
Quote Reply
Re: [colintho] can I limit the characters on the link page? In reply to
I guess what he is saying is its not converting the HTML.
Quote Reply
Re: [SandraR] can I limit the characters on the link page? In reply to
Sorry about not being more specific, I'll try and explain what's happening:

I have about 40 links that are 'affiliate' links, these use 'JavaScript' for displaying a short editorial and it is part of the 'JavaScript' code that is appearing in the 'shortened description.

***This is the text for the 'description' field ******


Swinton Caravan & Motorhome Insurance * * * <script language="JavaScript"src="http://creatives.omg2.com/GetEditorial.asp?Type=JS&EditorialID=523&MID=232&PID=552&AID=4729&CID=165099&WID=12783"></script>

***This is the link description, (on the detailed page) without being shortened******


Swinton Caravan & Motorhome Insurance * * * Safeguard, Motorhome and Caravan Insurance Specialists, are a division of Swinton Group Ltd. At Safeguard all our advisors are specialists in providing the cover you need. Apply online today.



***This is the link description, when it has been shortened (note that I had the character limit set to 250******



Caravan & Motorhome Insurance * * * <script language="JavaScript" ...



I also had a description that used <b>bold tags</b> that was not converting the html when it had been shortened.

Any help appreciated.

Colin Thompson
Quote Reply
Re: [colintho] can I limit the characters on the link page? In reply to
Hi,

Mmm.. not sure its possible with the HTML stuff in it :/

This would stand more of a chance of working:

Code:
sub {

my $value = $_[0];
my $length= $_[1] || 75;

$value = s|<a href|<ahref|sig;

my @split = split / /, $value;
my $back;
my $char_length = 0;
foreach (@split) {
$char_length = $char_length + length($_);
$back .= " " . $_;
if ($char_length > $length) { last; }
}
$value = s|<ahref|<a href|sig;
return \$back;

}

...but you will still end up with it making stuff like:

Code:
<a href="http://www.domain.com">

...into just:

Code:
<a

(if the charter's limit end at that point)

Hope that helps.

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!

Last edited by:

Andy: Oct 3, 2007, 3:09 AM
Quote Reply
Re: [Andy] can I limit the characters on the link page? In reply to
Andy

thanks, you are ACE for 'support'

I've changed the code as suggested and restored a few of the 'javascript' links

All works OK at present

Many thanks
Colin Thompson
Quote Reply
Re: [colintho] can I limit the characters on the link page? In reply to
Hi,

No problem. I've made a little change, that should hopefully stop the problem I mentioned in my above post (i.e cutting off after <a )

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] can I limit the characters on the link page? In reply to
I tested it and it works lovely :)

Awesome global Andy so much better than doing field limits.