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

Active categories

(Page 1 of 2)
> >
Quote Reply
Active categories
I would like to have a listing of "active" categories, that is, categories containing new links.

I thought I could do something template-based with <%if Has_New_Links eq 'Yes'%> etc., but can't get it to work, and now think I need a global to do this. I've tried something like:

Code:
sub {
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY ID DESC');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
my $cat_db = $DB->table('Category');
my @root_cats = $cat_db->select ['Full_Name']->fetchall_list;
...

}
return $output;
}
... but can't get it right.

Can anyone help, please?

John
Quote Reply
Re: [gotze] Active categories In reply to
I've just the following tag in the category template:

<%if Number_of_Links '>' '0'%>
Quote Reply
Re: [Alba] Active categories In reply to
Alba,

I don't think that's it. That just shows categories with something in them, doesn't it?

I want to show just categories (including subcats) that have new links in them.
Quote Reply
Re: [gotze] Active categories In reply to
What about <%if Has_New_Links eq 'Yes'%>
and <%if Has_Changed_Links eq 'Yes'%> if you want categories with updated links.

Not sure if this would work to show subcategories though.
Quote Reply
Active categories global In reply to
A bit of progress on this front... this global does (almost) what I need:
Code:
sub {
my $output;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Name');
my $sth = $cat_db->select ({Has_New_Links => 'Yes'} );
while (my $cat = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('newcategory', $cat);
}
return $output;
}
Example

I've created a new template, newcategory, that uses <%Full_Name%> and <%Name%>.

The problem is that Full_Name is "Full Name" and not "Full_Name", and that the urlified tag doesn't work here. I've met this problem before, and thought the solution would be something like this:

Code:

sub {
my $output;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Name');
my $sth = $cat_db->select ({Has_New_Links => 'Yes'} );
while (my $cat = $sth->fetchrow_hashref) {
my $path = $cat_db->as_url($cat->{Full_Name});
$output .= Links::SiteHTML::display ('newcategory', $path);
}
return $output;
}

Can anyone see what is wrong here? (I can't)

Another question: With all the new loop-stuff in GLinks, is there an easier way to do this??

John
Quote Reply
Re: [gotze] Active categories global In reply to
Ah, one more thought ... well, challenge/cry for help, since this is beyond my programming skills ...

Know Technorati Tags? The way they display lists is interesting.

It would be neat to do something similar here Smile
Count the number of new links in each category, and give them a label depending on the number of links ...

Category A (11 new links) => class=bigger
Category B (7 new links) => class=big
Category C (3 new links) => class=normal
(if intervals are like 0-5 => normal, 6-10 => big, and +10 => bigger)

Any ideas?
Quote Reply
Re: [gotze] Active categories global In reply to
I have not given up. I have made some progress, but really would appreciate some helpCrazy

Issue 1: Active Tags

I am still struggling with the linkability issue.

This code:

Code:
sub {
my $output;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name');
my $sth = $cat_db->select ({Has_New_Links => 'Yes'} );
while (my $cat = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('newcategory', $cat);
}
return $output;
}
is fine except it doesn't create the right urls. I've tried as_url etc, but just can't get it to work.

This code, however:

Code:
sub {
my $output;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name');
my $sth = $cat_db->select ( ['Full_Name','Name'], { Has_New_Links => 'Yes' });
while (my ($cat,$name) = $sth->fetchrow_array) {
$cat =~ s/ /_/g;
my $cat1 = $cat;
$output .=qq~<a href="$CFG->{build_root_url}/$cat1">$name</a>, ~;
}
return $output;
}
works, but uses a cheap trick to create the right urls. I don't like having to hardcode the HTML.

So, why can't I get it to work with the template?

Issue 2: Technorati Tags-style
It is important to me to be able to style the output. Here is stuff I want to do:

Code:
<%if Number_of_Links > 50 or Has_New_Links eq Yes%>
<big>
<a href="/links/<%Full_Name%>"><%Name%></a>
</big>
<%else%>
<a href="/links/<%Full_Name%>"><%Name%></a>
<%endif%>

This can be used to present something like this (here: all categories, categories with more than 50 links or with new links have bigger font)

Now I just need to combine these two.

I'll promise to write up a reusable global and stuff if I get help getting it to work.

John
Quote Reply
Re: [gotze] Active categories In reply to
Keep it simple, all you need to do is use the Has_New_Links column. Do all the html generation in the code also:
Code:
sub {
my $category = $DB->table('Category');
$category->select_options('ORDER BY Full_Name');
my $sth = $category->select({ Has_New_Links => 'Yes' });
my @cats;
while (my $cat = $sth->fetchrow_hashref) {
$cat->{URL} = "$CFG->{build_root_url}/" . $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";
push @cats, $cat;
}
return { new_categories => \@cats };
}
In the loop, you can do your technorati tags:
Code:
<%nameofsub%>
<%loop new_categories%>
<a href="<%URL%>"<%if Number_of_Links > 50%> class="whatever"<%endif%>><%Name%></a>
<%endloop%>

Adrian

Last edited by:

brewt: May 10, 2005, 12:53 AM
Quote Reply
Re: [brewt] Active categories In reply to
 

Unable to compile 'nameofsub': Global symbol "$sth" requires explicit package name at (eval 17) line 4. Global symbol "$cat" requires explicit package name at (eval 17) line 6. Global symbol "$sth" requires explicit package name at (eval 17) line 6. Global symbol "$cat" requires explicit package name at (eval 17) line 7. Global symbol "$cat" requires explicit package name at (eval 17) line 7. Global symbol "$cat" requires explicit package name at (eval 17) line 8. Global symbol "@gcats" requires explicit package name at (eval 17) line 10.
Quote Reply
Re: [brewt] Active categories In reply to
Thanks Adrian,

I'm afraid this doesn't work :-(
Code:
Unable to compile 'CategoriesWithNewLinks': Global symbol "$sth" requires explicit package name at (eval 16) line 4.
Global symbol "$cat" requires explicit package name at (eval 16) line 6.
Global symbol "$sth" requires explicit package name at (eval 16) line 6.
Global symbol "$cat" requires explicit package name at (eval 16) line 7.
Global symbol "$cat" requires explicit package name at (eval 16) line 7.
Global symbol "$cat" requires explicit package name at (eval 16) line 8.
Global symbol "@gcats" requires explicit package name at (eval 16) line 10.

What's gcats??
Quote Reply
Re: [gotze] Active categories In reply to
heh, fixed typo's. Come on guys, those were just simple bugs, you should have been able to figure it out!

Adrian

Last edited by:

brewt: May 10, 2005, 12:52 AM
Quote Reply
Re: [brewt] Active categories In reply to
Just thinking about this a little more and there is one problem with using Has_New_Links - Has_New_Links will be set even if there are no new links directly in it. If any of its subcategories has a new link in it then it will have Has_New_Links set. So if this isn't what you want, you'll have to go the slower route and select the links which are new (isNew), and figure out which categories those links belong to (pretty much what you had at first).

Adrian

Last edited by:

brewt: May 10, 2005, 12:58 AM
Quote Reply
Re: [brewt] Active categories In reply to
Not me Crazy

Thanks!
Quote Reply
Re: [brewt] Active categories In reply to
Wunderbar!

Thanks again, Adrian. Much appreciated.

John
Quote Reply
Re: [gotze] Active categories In reply to
Might want to recopy the whole chunk of code - I fixed it up a while ago to generate a proper URL.

Adrian
Quote Reply
Re: [brewt] Active categories In reply to
And you might want to sort by just Name instead of Full_Name, since when listing them by Name, it looks like they're randomly sorted :)

Adrian
Quote Reply
Sorting In reply to
Thanks again, Adrian. Yes, I did change
Code:
$category->select_options('ORDER BY Full_Name');
to
Code:
$category->select_options('ORDER BY Name');
so that the list is sorted alphabetically.

I also made a variation of the global, which I call AllCats:
Code:
sub {
my $category = $DB->table('Category');
$category->select_options('ORDER BY Name');
my $sth = $category->select( ['Has_New_Links','Number_of_Links','Name','Full_Name'] );
my @cats;
while (my $cat = $sth->fetchrow_hashref) {
$cat->{URL} = "$CFG->{build_root_url}/" . $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";
push @cats, $cat;
}
return { new_categories => \@cats };
}
That produces this page showing all my categories, with highlighted ones with new or many links.

The only remaining issue is the issue with Has_New_Links mentioned above. That's beyond my programming skills, so I hope someone will pick up on this.

John
Quote Reply
Re: [gotze] Sorting In reply to
Hi
I'm using your sub
Code:
sub {
my $category = $DB->table('Category');
$category->select_options('ORDER BY Name');
my $sth = $category->select( ['Has_New_Links','Number_of_Links','Name','Full_Name'] );
my @cats;
while (my $cat = $sth->fetchrow_hashref) {
$cat->{URL} = "$CFG->{build_root_url}/" . $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";
push @cats, $cat;
}
return { new_categories => \@cats };
}

and I'm calling it like this
Code:
<%tags%>
<%loop new_categories%>
<%if Number_of_Links > 50 or Has_New_Links eq Yes%>
<big>
<a href="/<%Full_Name%>"><%Name%></a>
</big>
<%if Number_of_Links < 50 or > 25%>
<a href="/<%Full_Name%>"><%Name%></a>
<%else%>
<small>
<a href="/<%Full_Name%>"><%Name%></a>
</small>
<%endif%>
<%endloop%>

I'm getting an output, BUT some the url of all links with two or more words and spaces between are without underscore _ ???
Does anyone know how to fix this?

Thanks
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Sorting In reply to
Hi,

You sure?

as_url() should automatically convert " " to "_".

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] Sorting In reply to
Andy wrote:
Hi,

You sure?

as_url() should automatically convert " " to "_".

Cheers

Hi Andy,
you can see the tag cloud here
http://www.gpaed.de/g-tags

In the first line see "basale Foerderung" there is the _ missing, and in all other categories with more than one word ?
Thanks
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Andy] Sorting In reply to
Hi,

I see the problem :P

You use:

Code:
<a href="/<%Full_Name%>"><%Name%></a>

..but you need to use:

Code:
<a href="<%URL%>"><%Name%></a>

=)

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] Sorting In reply to
Andy wrote:
Hi,

I see the problem :P

You use:

Code:
<a href="/<%Full_Name%>"><%Name%></a>


..but you need to use:

Code:
<a href="<%URL%>"><%Name%></a>


=)

Cheers

Hi Andy,
O.K. I did that, but now I have a part of the URL twice.
I think I have to change this part of the global:
Code:
sub {
my $category = $DB->table('Category');
$category->select_options('ORDER BY Name');
my $sth = $category->select( ['Has_New_Links','Number_of_Links','Name','Full_Name'] );
my @cats;
while (my $cat = $sth->fetchrow_hashref) {
$cat->{URL} = "$CFG->{build_root_url}/" . $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";
push @cats, $cat;
}
return { new_categories => \@cats };
}
Thanks
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Sorting In reply to
Mmm, you could try editing:

Code:
$cat->{URL} = "$CFG->{build_root_url}/" . $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";

..to:

Code:
$cat->{URL} = $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";

..but from memory, as_url() doesn't actually put the build_url_url in it - not 100% sure on that though =)

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] Sorting In reply to
Andy wrote:
Mmm, you could try editing:

Code:
$cat->{URL} = "$CFG->{build_root_url}/" . $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";


..to:

Code:
$cat->{URL} = $category->as_url($cat->{Full_Name}) . "/$CFG->{build_index}";


..but from memory, as_url() doesn't actually put the build_url_url in it - not 100% sure on that though =)

Cheers

Hi Andy,
Works fine on my site :-) Sometimes I think my site is reacting different from other glinks sites Blush

I would like to have a second smaller tag cloud.
Is there a way to cut of the output for example to 25 categories ??

Thanks
Matthias

Matthias
gpaed.de
Quote Reply
Re: [Matthias70] Sorting In reply to
Matthias70 wrote:
Hi Andy,
Works fine on my site :-) Sometimes I think my site is reacting different from other glinks sites Blush

I would like to have a second smaller tag cloud.
Is there a way to cut of the output for example to 25 categories ??

Thanks
Matthias

Hi Andy,
I found a solution on my own.
Just changed
Code:
$category->select_options('ORDER BY Has_New_Links DESC');
$category->select_options('ORDER BY Has_New_Links DESC', 'LIMIT 25');

Thanks
Matthias

Matthias
gpaed.de
> >