Gossamer Forum
Home : Products : Gossamer Links : Discussions :

display new links of a specific category?

(Page 1 of 2)
> >
Quote Reply
display new links of a specific category?
Hello,
actually we have the following global to display the latest 5 links on home page:

sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY ID DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}


what if i would like to display only the new links of a single category and not of all categories.

Waiting to hear from you

Many Thanks
Antoine

Last edited by:

antoined: Oct 9, 2004, 9:18 AM
Quote Reply
Re: [antoined] display new links of a specific category? In reply to
Any hint please????
A
Quote Reply
Re: [antoined] display new links of a specific category? In reply to
Give this a go; (untested!)

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 }, { isNew => 'Yes', isValidated => 'Yes' });
} else {
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
}

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

return $output;
}

Call with;

Code:
<%global_name($ID)%>

...in category.html

Hope that works Smile

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] display new links of a specific category? In reply to
You must be a genius!!! it works very good.

I only changed :

my $current_catid = $_[0] || 0;
to
my $current_catid = $_[10] || 10; (where 10 is the category number in question)

Many thanks

Antoine
ps: will it retrieve also the links from its subdirectories???

Quote Reply
Re: [antoined] display new links of a specific category? In reply to
Quote:
You must be a genius!!! it works very good.

Angelic

Quote:
ps: will it retrieve also the links from its subdirectories???

Unfortunatly not. It will only grab the "new" links from the category they are in.

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] display new links of a specific category? In reply to
In Reply To:
Quote:
ps: will it retrieve also the links from its subdirectories???

Unfortunatly not. It will only grab the "new" links from the category they are in.

Cheers


Hello Andy,

Is there a way to make it happen? I mean a global or plugin or something, where it will be able to display "new", "top/popular" links from its sub-categories too?

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [NeedScripts.Com] display new links of a specific category? In reply to
Sure ... but I really don't have time to write something to do it :( (I'm not at the office this week).

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: [NeedScripts.Com] display new links of a specific category? In reply to
Hi Vishal,

Something like this, depending on what you want:

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_Time DESC Limit 10');
$sth = $search_db->select (['Links.*'], GT::SQL::Condition->new(['CategoryID', 'IN', $all_ids], ['isValidated', '=', 'Yes', 'isNew', '=', 'Yes']) );
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;
}
Quote Reply
Re: [afinlr] display new links of a specific category? In reply to
How I call to the global?
Quote Reply
Re: [nir] display new links of a specific category? In reply to
You need to paste the global in the blank box at the bottom of admin->build->template globals and give it a name. Then where you want to use it put <%nameofglobal($ID)%> where 'nameofglobal' is the name you have given it.
Quote Reply
Re: [afinlr] display new links of a specific category? In reply to
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_Time DESC Limit 10');
$sth = $search_db->select (['Links.*'], GT::SQL::Condition->new(['CategoryID', 'IN', $all_ids], ['isValidated', '=', 'Yes', 'isNew', '=', 'Yes']) );
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;
}
-------------------------------------------------------------------
I try to use this but I don't know where I need to put the number of the category that I want to display the new links from here and here subcategory.

Can anybody help me?

Last edited by:

nir: Nov 1, 2004, 3:32 AM
Quote Reply
Re: [nir] display new links of a specific category? In reply to
You should be able to call it with;

<%global_name($ID)%>

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: [afinlr] display new links of a specific category? In reply to
Hello Laura,

Thanks a lot you are life saver :)

Vishal

Vishal
-------------------------------------------------------
Quote Reply
Re: [Andy] display new links of a specific category? In reply to
Hi Andy
I have a pagebuilder and I want to make special page for every category so I need to give the id of the category.
Quote Reply
Re: [nir] display new links of a specific category? In reply to
Yeah, I guess you would have to hard-code it. I.e;

<%global_name('1234')%>

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] display new links of a specific category? In reply to
I get
A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval 12) line 10.
Quote Reply
Re: [nir] display new links of a specific category? In reply to
Try changing;

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

..to;

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

... does that give a more detailed error message?

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: [nir] display new links of a specific category? In reply to
Sorry - my fault. Change 'Add_Time' to 'Add_Date'.
Quote Reply
Re: [Andy] display new links of a specific category? In reply to
Andy thanks thanks and thanks
The problem was in this ('ORDER BY Add_Time DESC Limit 10'); I change the Add_Time to Add_Date.

Last question :) what I need to change so the output will go to a specific Templates
$output .= Links::SiteHTML::display('link', $link);
Quote Reply
Re: [nir] display new links of a specific category? In reply to
No worries :)

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

... and then make a new template called "NEW_link.html" (only used that name as an example... you can call it what you want =)).

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: [afinlr] display new links of a specific category? In reply to
It seems these lines are unnecessary in your global:
my $category_url = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
my $detailed_url = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";

Just noted that the $category_url and $detailed_url is not reused anywhere in the global.


I thought I should bring your attention to this.

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
Tongue Good point.

Those lines should be

$link->{'category_url'} = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
Quote Reply
Re: [afinlr] display new links of a specific category? In reply to
Let me post the full global code, containing changes of the thread.


Global task: Display the latest the new 10 links only of a single category.
Global code:
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', 'isNew', '=', '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;
}


Global Usage:
<%new_links_of_category('1234')%>

1234 = category id of specific category


I also posted the code to Links SQL/Globals resources page.

It would be good idea to have more & more globals posted into the resource page above...

Laura, could you also post some globals to the Links SQL/Globals resources 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: [webmaster33] display new links of a specific category? In reply to
Hi,

I've been very short of time the past few months, but I'm still packaging up the UltraWidgets Toolbox. It will contain most of our globals and code extensions that we've posted, and if anyone wants their globals included, send them to me via PM.

The globals are going to located in a Plugins::Ultra::Toolbox module. We are going to prefix all our modules like that, and the first set will be the updated releases I've been talking about for the past few months.

Rather than having to edit/load a global, you'll be able to just select from the list of available functions, and include them like:

<%Plugins::Ultra::Toolbox::Top_10%>

Most will have the ability to accept parameters, as well as use current defaults. It's a tad more confusing in some ways now, as more data is being passed through, but somewhat less confusing as that data is more well containerized.

There will be two versions, a "Lite" and a "Pro."

THe lite will be free, and eventually should have an interface for adding new functions as posted here. (Plugins::Ultra::Toolbox::Custom::nnnn)

The pro will contain advanced functions and routines, and extra features for maintaining your site's add-ons.

If you'd like to have your globals included in the function end (free/open functions only) send them, or a pointer to the thread in a PM. Eventually, after the first release or two, we'll go back and look for functions for potential inclusion, but you can help by pointing us to them.

This is something I've been working on for several years, and it's just about ready to go with the release of GL3. (Part of the current delay is creating CSS compliant code fragments).


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] display new links of a specific category? In reply to
Good idea.

I'm sure it will be really appreciated by LSQL users, if it would be worked out correctly...


Do you plan such feature for DBManSQL, too?

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