Gossamer Forum
Home : Products : Gossamer Links : Discussions :

display new links of a specific category?

(Page 2 of 2)
> >
Quote Reply
Re: [webmaster33] display new links of a specific category? In reply to
Hi,

I tried using this global and it gives me an error. I am using it on a dynamic page that is an addition to the template set (not factory). The error is:
A fatal error has occured:
GT::SQL::Table (140): Wrong argument passed to this subroutine. Must pass category id to children at blahblahblah/Category.pm line 404. Any ideas as per why the cat is not passed to the children?I also used both ($ID) and ('ID') in the tag....just as a side note as well.What my ultimate goal for this is to show 6 categories on a seperate page with all new links below each category including the breadcrumb for each link. Like this:
catname: subcatname: sub sub cat name: sub sub sub catname (all linked)
Link.html information for that one link

Thanks Brian

Quote Reply
Re: [Teambldr] display new links of a specific category? In reply to
Do you pass in a valid category id?

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: [Teambldr] display new links of a specific category? In reply to
Try this code:
Code:
sub {
my $cat_id = shift;
my $new_nr_limit = shift || 10; # Default is 10
($cat_id && $cat_id =~ /^\d+$/)
|| return "Invalid category ID passed to new_links_of_category global: $cat_id<br>\n";
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC Limit $new_nr_limit);
my $sth = $db_obj->select (['Links.*'], GT::SQL::Condition->new(
['CategoryID', 'IN', $all_ids],
['isValidated', '=', 'Yes', 'isNew', '=', 'Yes'])
);
my $output = qq~
<hr>~;
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;
}

Usage:
<%new_links_of_category(1234, 10)%>

1234 = category id of specific category
10 = new links number limit - display last 10 new links

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

Last edited by:

webmaster33: Aug 3, 2005, 1:37 AM
Quote Reply
Re: [webmaster33] display new links of a specific category? In reply to
Hi,

Thanks.

I did get it working by using two globals. One to grab the cat info and the other being the new cat links above. Since it was a custom template the cat info had to be pulled in.

Thanks

Brian
Quote Reply
Re: [Teambldr] display new links of a specific category? In reply to
Would be fair to share your solution with the community...

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] display new links of a specific category? In reply to
This is a really nice global!

I'm just wondering how to manage to show the newest 10 Links of the actual sub-category instead of the top-category.

Regards,
Manu

Shopping Portal Shop-Netz.de® | Partnerprogramme | Flugreisen & Billigflüge | KESTERMEDIA e.K. | European Affiliate Marketing Forum.

Last edited by:

ManuGermany: Aug 5, 2005, 3:20 AM
Quote Reply
Re: [ManuGermany] display new links of a specific category? In reply to
Quote:
This is a really nice global!
It's not my global. I just polished it.
Credits should go to Andy and Laura!


Quote:
I'm just wondering how to manage to show the newest 10 Links of the actual sub-category instead of the top-category.
Just use the category ID of the sub-category, and you are done Wink

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] display new links of a specific category? In reply to
Quote:
Just use the category ID of the sub-category, and you are done


Yes that's true, but how to do this?

I use the Link-ID for calling the sub [<%sub_name(ID)%>]

Regards,
Manu

Shopping Portal Shop-Netz.de® | Partnerprogramme | Flugreisen & Billigflüge | KESTERMEDIA e.K. | European Affiliate Marketing Forum.

Last edited by:

ManuGermany: Aug 5, 2005, 8:47 AM
Quote Reply
Re: [ManuGermany] display new links of a specific category? In reply to
It seems you want something different...
Could you describe, exactly what do you want?

Do you want listing new links in categories multiple level deep?

Could you post an example how would you want to look the result HTML code?

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] display new links of a specific category? In reply to
Example:

A Link is in the category TopCat > Sub1Cat > Sub2Cat

Now if I call the sub using the link's ID [<%sub($ID)%> on Detailed Page], it delivers the 10 newset links of TopCat.

But I want to get the 10 newest Links oft Sub2Cat!

Regards,
Manu

Shopping Portal Shop-Netz.de® | Partnerprogramme | Flugreisen & Billigflüge | KESTERMEDIA e.K. | European Affiliate Marketing Forum.

Last edited by:

ManuGermany: Aug 5, 2005, 10:15 AM
Quote Reply
Re: [ManuGermany] display new links of a specific category? In reply to
Ok.

At that point, the question is:
Why is on the Sub2Cat Detailed page, the TopCat ID delivered?

It is something, that can be resulted by a plugin, a global, or the LSQL itself.
It is also possible that the $ID is 0, resulting to dislay a top category.


So try to display the ID using this: <%ID%>
What's the result?


Also try to think, what is resulting TopCat ID on the Sub2Cat Detailed page???

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: [ManuGermany] display new links of a specific category? In reply to
Try the following code:
Code:
sub {
my $cat_id = shift;
my $new_nr_limit = shift || 10; # Default is 10
($cat_id && $cat_id =~ /^\d+$/)
|| return "Invalid category ID passed to new_links_of_category global: $cat_id\n";
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC Limit $new_nr_limit');
my $sth = $db_obj->select (['Links.*'],
GT::SQL::Condition->new(
['CategoryID', 'IN', $all_ids],
['isValidated', '=', 'Yes',
'isNew', '=', '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;
}

There was a missing single quote in the global I earlier posted. Fixed it now.
I don't think however, that this was causing the mentioned problem.
The questions from my previous post are still valid.

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] display new links of a specific category? In reply to
I got it!

The problem was, that in all the postings above the link-<%ID%> was used instead of the <%category_id%> which is the correct id to use for the sub!


Because on detailed pages no category-id is available, I'm using a second sub to get a link's category_id:

get_cat_id:

Code:

sub {
my $tags = shift;
my $id = $tags->{'ID'};
my $db = $DB->table ('Category','CatLinks');
$db->select_options('LIMIT 1');
my $catid = $db->select ( { LinkID => $id }, ['ID'] )->fetchrow_array;
return $catid;
}


related_links:

Code:

sub {
my $cat = shift;
my $LinkID= shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC Limit 4');
my $sth = $db_obj->select (['Links.*'], GT::SQL::Condition->new(
['CategoryID', 'IN', $all_ids],
['Links.ID', '!=', $LinkID, 'isValidated', '=', 'Yes', 'isNew', '=', 'Yes'])
);
my $output = qq~<br>~;
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 .= qq~<CENTER><TABLE WIDTH="80%" BORDER="0" CELLSPACING="0" CELLPADDING="2">~;
$output .= Links::SiteHTML::display('link', $link);
$output .= qq~</TABLE></CENTER>~;
}
return $output;
}



And on the detailed.html:

Code:
<%related_links($get_cat_id, $ID)%>

Regards,
Manu

Shopping Portal Shop-Netz.de® | Partnerprogramme | Flugreisen & Billigflüge | KESTERMEDIA e.K. | European Affiliate Marketing Forum.

Last edited by:

ManuGermany: Aug 6, 2005, 5:36 AM
Quote Reply
Re: [ManuGermany] display new links of a specific category? In reply to

I use this code

sub

{

my $cat = shift;

my ($output,$sth,$link);

my $all_ids = $DB->table('Category')->children($cat);

push @$all_ids, $cat;

my $search_db = $DB->table('Links','CatLinks','Category');

$search_db->select_options ('ORDER BY Add_Date DESC Limit 10');

$sth = $search_db->select (['Links.*'], GT::SQL::Condition->new(['CategoryID', 'IN', $all_ids], ['isValidated', '=', 'Yes', 'isNew', '=', 'Yes']) ) || return $GT::SQL::error;

my $output = qq~<br><hr>~;

while ($link = $sth->fetchrow_hashref)

{

my $category_url = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";

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

$output .= Links::SiteHTML::display('link', $link);

}

return $output;

}

The problem is when I insert the same link for 2 or 3 category I get the same link more than one time in the list of the new link.


Quote Reply
Re: [webmaster33] display new links of a specific category? In reply to
1 - How about if I want to display only the name of the cat/subcat for the specific cat/subcat that is being displayed.
2 - and what about if I want to display all the links instead of just the new ones.
thanks much
Mark
Quote Reply
Re: [Mark2] display new links of a specific category? In reply to
Code:
sub {
my $cat_id = shift;
my $new_nr_limit = shift || 10; # Default is 10
($cat_id && $cat_id =~ /^\d+$/)
|| return "Invalid category ID passed to new_links_of_category global: $cat_id\n";
my $all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC Limit $new_nr_limit');
my $sth = $db_obj->select (['Links.*'],
GT::SQL::Condition->new(
['CategoryID', 'IN', $all_ids],
['isValidated', '=', 'Yes',
'isNew', '=', '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;
}

Quote:
1 - How about if I want to display only the name of the cat/subcat for the specific cat/subcat that is being displayed.
Just change the link.html template file and use the correct field name...


Quote:
2 - and what about if I want to display all the links instead of just the new ones.
I highlighted the affecting part with red just remove them and you are fine.

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] display new links of a specific category? In reply to
Thank you for your help...
for item 2 below:

I am trying to accomplish what I mentioned in the following thread:
http://www.gossamer-threads.com/...apsed;guest=14318546

Your changes seems fine; however, i am looking at your code, and still see that you are still checking for the Condition->new
GT::SQL::Condition->new(

Is that true...

What I am trying to do is this:
I want to show all categories/sub on home page in the position that I want....
Another thread is like that:
http://www.gossamer-threads.com/...;;page=unread#unread


For item 1 below, I am trying to put the category name and under it the links

Nissan Pathfinder
- link1
- link2
- link3

Thank you much for your help.. and sorry I logged this one several times and no one seemed to answer it other then you...
thank you again..
Mark
Quote Reply
Re: [Mark2] display new links of a specific category? In reply to
The Condition->new means not those links are listed which are new. It's an object oriented programming style.
The new links are selected in this code:
'isNew', '=', 'Yes'
Just remove it.

It seems you want to do a link grouping by category.
This would need additional coding using GROUP BY sql statement, then checking the category difference from the last one, and print category name, if different.

Other solution would be to put links into a grouped data structure in the while loop, then print them grouped based on this structured variable.

Contact me privately if you want me to create it for you.

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] display new links of a specific category? In reply to
For now, I am almost there,
I just modified this code a little bit to display all links inside a specific cat/subcat. However, what I am missing is the category name of those links (means the title of the links displayed).
This is where I am at:

Code:

sub {
my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC Limit 10');
my $sth = $db_obj->select (['Links.*'],
GT::SQL::Condition->new
(
['CategoryID', 'IN', $all_ids],
['isValidated', '=', 'Yes'])
);
my $output = qq~<br><hr>~;
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;
}


and I am calling it via
<%display_category('234')%>

and that is returning to me all the links but without the name of the category
thanks
Quote Reply
Re: [Mark2] display new links of a specific category? In reply to
Just use <%Name%> in your template.

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] display new links of a specific category? In reply to
Well! that may work, but I think it will dump all category names instead of the specific category name.
Want I am looking for is the same way that I call the global to display the links...
something like:

<%display_category('234')%> - which will display all the links inside category with ID 234
and now:
<%display_category_name('234')%> - which should display the name of the category of 234 (e.g. Nissan Pathfinder(linked))

thanks again...
Mark
Quote Reply
Re: [Mark2] display new links of a specific category? In reply to
Actually, I find this code is more relevent as it displays all the links inside a subsub, instead of displaying recorsively the links inside the tree (links in main + links in sub + links in subsub) for (main>sub>subsub)
But as usual, I still do not have the subsub name displayed??!!! (need seperate global to display it if I pass the category ID.

Code:

sub {

my $current_catid = $_[0] || 0;

# Displays the newest links on the home page.
my ($output,$sth,$link);

my $search_db = $DB->table('CatLinks','Links');
$search_db->select_options ('ORDER BY ID DESC Limit 5');

my $sth;
if ($current_catid > 0) {
$sth = $search_db->select ( { CategoryID => $current_catid }, { isValidated => 'Yes' });
}
else {
$sth = $search_db->select ( { isValidated => 'Yes' });
}

while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}

return $output;
}

thanks again...
Mark
Quote Reply
Re: [ManuGermany] display new links of a specific category? In reply to
   
Hi,

since the upgrade to Links3x the code below (and posted earlier in this thread) doesn't work any more.

I'll just get an error and detaild pages weren't build.

I can't work out what the problem since the LinksUpgrade is.

Does anyone here in the forum has a clue?



get_cat_id:

Code:

sub {
my $tags = shift;
my $id = $tags->{'ID'};
my $db = $DB->table ('Category','CatLinks');
$db->select_options('LIMIT 1');
my $catid = $db->select ( { LinkID => $id }, ['ID'] )->fetchrow_array;
return $catid;
}



related_links:

Code:

sub {
my $cat = shift;
my $LinkID= shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC Limit 4');
my $sth = $db_obj->select (['Links.*'], GT::SQL::Condition->new(
['CategoryID', 'IN', $all_ids],
['Links.ID', '!=', $LinkID, 'isValidated', '=', 'Yes', 'isNew', '=', 'Yes'])
);
my $output = qq~<br>~;
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 .= qq~<CENTER><TABLE WIDTH="80%" BORDER="0" CELLSPACING="0" CELLPADDING="2">~;
$output .= Links::SiteHTML::display('link', $link);
$output .= qq~</TABLE></CENTER>~;
}
return $output;
}




And on the detailed.html:

Code:
<%related_links($get_cat_id, $ID)%>
[/code]
Regards,
Manu

Shopping Portal Shop-Netz.de® | Partnerprogramme | Flugreisen & Billigflüge | KESTERMEDIA e.K. | European Affiliate Marketing Forum.
> >