Gossamer Forum
Quote Reply
help with keyword global
Hey! I need help with this global found on the forum somewhere. I need it not to list the keyword more than once. Any ideas?

sub { my $tags = GT::Template->tags; my $cat = $tags->{category_name}; $cat =~ s|/|,|g; my $sub_cat = join(",", map { join(",", split(/\//, $_->{Full_Name})) } @{$tags->{category_loop}}); my $keywords = $cat; $keywords .= $sub_cat if $sub_cat; return lc $keywords; }

Smile

Thanks
Quote Reply
Re: [blackbird] help with keyword global In reply to
Never mind. I'm a retard. It seems to be working now without duplicate keywords.
Thanks,
Blackbird
Quote Reply
Re: [blackbird] help with keyword global In reply to
I do have another problem though. Some categories are only letters like category a, b, c, and so on. How can the global be changed to exclude categories with too few chararacters? The keywords for instance would have to contain at least 3 characters to be added.
Thanks,
Blackbird
Quote Reply
Re: [blackbird] help with keyword global In reply to
I'm not quite sure how this global works (I'm not familiar with the map{} function), but try adding this before the return lc $keywords; bit.

Code:

my @exploded = split(",",$keywords);
my @back;

# if a listing is less than 2 chars, then dont put
# it into the new array...simply skip it....
foreach (@exploded) { if ($_ =~ /[\W\d\w]/i) { push(@back,$_); } }

$keywords = join(",",@back);

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!
Quote Reply
Re: [Andy] help with keyword global In reply to
I don't think that code does what you think it does =)
Quote Reply
Re: [Andy] help with keyword global In reply to
Eugh...should be;

foreach (@exploded) { if ($_ =~ /[\W\d\w]{2,20}/i) { push(@back,$_); } }

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] help with keyword global In reply to
Code:
my @long_enough = grep length > 2, @exploded;

Cool

Last edited by:

Paul: Jun 24, 2003, 5:56 AM
Quote Reply
Re: [Paul] help with keyword global In reply to
I am getting errors. Can you show me how to put this code my @long_enough = grep length > 2, @exploded;

in here:

Code:
sub {
my $tags = GT::Template->tags;
my $cat = $tags->{category_name};

$cat =~ s|/|,|g;

my $sub_cat = join(",", map { join(",", split(/\//, $_->{Full_Name})) } @{$tags->{category_loop}});

my $keywords = $cat;
$keywords .= $sub_cat if $sub_cat;

return lc $keywords
}

Thanks,
Blackbird

Last edited by:

Paul: Jun 25, 2003, 7:00 AM
Quote Reply
Re: [blackbird] help with keyword global In reply to
This should work;

Code:
sub {
my $tags = GT::Template->tags;
my $cat = $tags->{category_name};

$cat =~ s|/|,|g;

my $sub_cat = join(",", map { join(",", split(/\//, $_->{Full_Name})) } @{$tags->{category_loop}});

my $keywords = $cat;
$keywords .= $sub_cat if $sub_cat;

my @exploded = split(",",$keywords);

# if a listing is less than 2 chars, then dont put
# it into the new array...simply skip it....
my @long_enough = grep length > 2, @exploded;

$keywords = join(",",@long_enough);

return lc $keywords
}

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] help with keyword global In reply to
I am getting some crazy keywords. Here is an example:

meta name="keywords" content="pharmacy,drugs and medicationspharmacy,drugs and medications,pharmacy,drugs and medications,analgesics and anti-inflammatories,pharmacy,drugs and medications,antianxiety agents,pharmacy,drugs and medications,antiasthmatic,pharmacy,drugs and medications,antibiotics,pharmacy,drugs and medications,antidepressants,pharmacy,drugs and medications,antihistamines,pharmacy,drugs and medications,antipsychotics,pharmacy,drugs and medications,pharmacy,drugs and medications,beta blockers,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,lipid-lowering agents,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,stimulants,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications,pharmacy,drugs and medications

any idea what is wrong?
Thanks,
Blackbird
Quote Reply
Re: [Andy] help with keyword global In reply to
Would it be easier to exclude certain keywords and list all the letters of the alphabet? There seems to be a problem where the categories are split and joined. It looks as though the catagories are joined with subcategories using the previous script.

Any help would be appreciated.
Thanks,
Blackbird
Quote Reply
Re: [Andy] help with keyword global In reply to
Okay, this is getting real close except when the keywords are joined it combines the last category word with the first sub category word as a key word. I need a "," after the last category. Can anybody fix this join statement?

Here is what works except for above:

sub { my $tags = GT::Template->tags;
my $cat = $tags->{category_name};
$cat =~ s|/|,|g; my $sub_cat = join(",", map { $_->{Name} } @{$tags->{category_loop}});
my $keywords = $cat; $keywords .= $sub_cat if $sub_cat;
my @exploded = split(",",$keywords);
my @long_enough = grep length > 2, @exploded;
$keywords = join(",",@long_enough);
return lc $keywords }

Thanks,
Blackbird
Quote Reply
Re: [blackbird] help with keyword global In reply to
This will work but requires two globals one for categories and another for sub categories. Hope someone else can benefit from this.

Metasubcat


sub { my $tags = GT::Template->tags;
my $sub_cat = join(",", map { $_->{Name} } @{$tags->{category_loop}});
my $keywords .= $sub_cat if $sub_cat;
my @exploded = split(",",$keywords);
my @long_enough = grep length > 2, @exploded;
$keywords = join(",",@long_enough);
return lc $keywords }


metacat

sub { my $tags = GT::Template->tags; my $cat = $tags->{category_name}; $cat

=~ s|/|,|g; my $keywords = $cat; my @exploded = split(",",$keywords); my

@long_enough = grep length > 2, @exploded; $keywords = join(",",@long_enough);

return lc $keywords }

Just enter in like this in your category template:

<%metacat%>,<%metasubcat%>

This takes care of the seperating category from subcategory problem and eliminates single letters of the alphabet from keywords. Someone else may be able to get this in one global, but not me.

PirateBlackbird