Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Lastlink by specific main category

Quote Reply
Lastlink by specific main category
Hi All,

How to list 5 lastlink for specific category, for example, i have 3 main category:

1-Ringtones
2-Operator Logo
3-Picture Message

On each main category have a multi subcategory, what i need is a global tag to list down 5 from each main category, let say:

Ringtones:
<%ringtones> - I can put this tag anywhere on any template for list 5 last ringtones on my database

Operator Logo:
<%operator_logo%> - I can put this tag anywhere on any template for list 5 last operator logo on my database ....etc

I just found the global tag below for list 5 lastlin on each main category, i think it can be specific, but how and please help.

Code:
sub {
my ($rec) = @_;
my $id = $rec->{ID};
my $db = $DB->table ('Links','CatLinks');
$db->select_options ('ORDER BY ID DESC', 'LIMIT 5');
my $sth = $db->select ( { 'CatLinks.CategoryID' => $id}, ['Links.ID', 'Links.Title', , 'Links.URL'], { isValidated => 'Yes'} );

my $toplinks;
while (my ($id,$name,$url) = $sth->fetchrow_array) {

$toplinks .= "<li><a href='$url'>$name</a>";

}
return $toplinks;
}


Thank you.
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
I assume that you want the last five links in the main category and all its subcategories. If so, you could try this global. If you name it ringtones and put the ID of ringtones in as the $cat_id variable then you can call it with <%ringtones%> as you want. Then you'll have to create similar globals for the other two categories. You can modify the html so that it gives what you want. I haven't tested it so it might need debugging but its just a slight modification from one I had written for someone else so hopefully it should work.

sub {
my ($all_ids,@list);
my $cat_id = 'Put ID of the main category here';
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $link_db = $DB->table('Links','CatLinks','Category');
$link_db->select_options ("ORDER BY Add_Date DESC LIMIT 5");
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', \@$all_ids);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
push @list, $link;
}

my $output;
foreach my $link (@list) {
# Set the category url
my $url = $DB->table('Category')->as_url($link->{'Full_Name'});
# Set the detailed_url
my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
$output .= qq~<li><a href="$CFG->{build_root_url}/$url/">$link->{'Name'}</a> (Added: $link->{'Add_Date'})<br><a href="$detailed_url">$link->{'Title'}</a>~;
}

return $output;

}
The UK High Street
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
Thank you so much afinlr, i didnt test it yet, soon i will test it and i tell you the result ..thanks again
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
Hi afinlr,

Its work, thank you so much.

Other thing is, how can i listing the subcategory by specific of category? do u have any idea for it ?

For example,
<%ringtonescat%> - This global tag will listing all the subcategory under the directory of 'Ringtones'

Thanks again and please help.
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
This is a similar global to the last one - i.e. the category id is hardcoded. (You could easily use one global instead of 3 by passing the id into the global - just change the cat_id line to $cat_id = shift; and call it with <%nameofglobal('2')%> for category id 2 or <%nameofglobal($ID)%> for the current category.)

sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id = 'put the id here';
my $all_ids = $cat_db->children($cat_id);
$cat_db->select_options('ORDER BY Full_Name');
my $cond = GT::SQL::Condition->new('ID', 'IN', \@$all_ids);
my $sth = $cat_db->select ( $cond, ['Full_Name','Name'] );
while (my ($cat,$heading) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($cat);
$output .= qq~<li><a href="$CFG->{build_root_url}/$url">$heading</a>~;
}
return $output;
}

Laura.
The UK High Street
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
Hi,
I am trying to display the contents of a specific (repeated) categeory. So instead of calling 'category id' here, can we call we a category name, lets say a category "restaurant" like <%nameofglobal('restaurant')%> . I will call this global fom category.html.

I assume that every category has a sub-category called "restaurant" . if category "restaurant" doesn't exist in the sub-category list, this global should not be called. How can i do that?

Thanks,
sve
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
This global looks similar to what i wanted. I wish to call a 'category name' in the current category, instead of id. I have lots of sub-cats, so i prefer using name rather than id.

sve
Quote Reply
Re: [vensub71] Lastlink by specific main category In reply to
Hi,

I think this is much more complicated. Unfortunately I really don't have time to think this through at the moment - the two globals above were simple changes from globals I had already written.

I assume that your repeated restaurants subcats are not the same subcat repeated but different subcategories which happen to have the same name. I think that the way to do this would be to get all the subcategory ids of the current category, look up their names, work out whether any of the names are 'restaurants' and if so return the output. You may need to ask for this as a custom modification job. Although - I do wonder whether you could do this with if statements in the subcategory.html template?

Well, I'm thinking about this more while writing itTongue

What about if you tried something like this - in your subcategory.html template add

<%if Short_Name eq 'Restaurants'%><%globalname($ID)%><%endif%>

(change globalname to whatever you call your global.) And then in the global, instead of the line

return $output;

put this line instead

return {restaurants => $output};

Then I think you can use the tag <%restaurants%> wherever it is you want the output further down the page.

I maybe way off track (its quite late here!) but I think this should work - you just need to sort out the global that you use so it gives you the output you want.

Laura.
The UK High Street
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
In the global should i replace the line
my $cat_id = 'put the id here'; with $cat_id = shift; ?
Quote Reply
Re: [vensub71] Lastlink by specific main category In reply to
Yes.
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
Hi afinlr,

Thank you so much, its work but i have problem with a category listing, let me explain the category i have on my database:

For example:

Code:
Ringtones-
-Antheme
-A
-B
-C - Z
-Pop
-A
-B
-C - Z
-Rock
-A
-B
-C - Z
-Jazz
-A
-B
-C - Z

What i need from the subcategory listing is only the main category after 'Ringtones' like Antheme - Jazz (for the future i will add more categories so it come easier without update to any page) and not all the subcategories inside Antheme etc.

Is it possible?

Please help and thank you so much.
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
Try this:

sub {
my $output;
my $cat_db = $DB->table('Category');
my $cat_id = 'put the id here';
$cat_db->select_options('ORDER BY Full_Name');
my $sth = $cat_db->select ( {'FatherID' => $cat_id}, ['Full_Name','Name'] );
while (my ($cat,$heading) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($cat);
$output .= qq~<li><a href="$CFG->{build_root_url}/$url">$heading</a>~;
}
return $output;
}
The UK High Street
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
Thank you so much afinlr, Its work, you are so helpful.


Thanks again.
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
I got fatal error. Please see the desc below.

A fatal error has occured:

GT::SQL::Table (22122): Invalid category id: HASH(0x8600e08) at GT::Base::_format_err line 5.
Quote Reply
Re: [vensub71] Lastlink by specific main category In reply to
Hi,

How can i print the output in 2 column or more, currently the output is only print with one column only.

Please help & Thank you so much.

Last edited by:

reenee: Apr 20, 2003, 10:13 AM
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
Please help ? Anybody out there ? Paul ? afinlr ? I really need this urgent, how should i print the lastlink in 2 or 3 column instead of single column?

Please help.
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
Something like this:

sub {
my $output=qq~<table width="100%"><tr><td width="50%">~;
my $cat_db = $DB->table('Category');
my $cat_id = 'put the id here';
$cat_db->select_options('ORDER BY Full_Name');
my $sth = $cat_db->select ( {'FatherID' => $cat_id}, ['Full_Name','Name'] );
my $total = $cat_db->count ( {'FatherID' => $cat_id}, ['Full_Name','Name'] );
my $breakpoint = int (($total+1)/2) + ( (($total+1) % 2) ? 1 : 0);
my $i=0;
while (my ($cat,$heading) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($cat);
($i > 0) and !($i % $breakpoint) and ($output .= qq~</td><td valign="top" width="50%">~);
$i++;
$output .= qq~<li><a href="$CFG->{build_root_url}/$url">$heading</a>~;
}
$output .= qq~</td></tr></table>~;
return $output;
}
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
Hi afinlr, Thank you so much for helping, for your information currently i'm using kind as below for showing the last 10 of category, how can i modify it to show on 2 column, thank you so much:

lastop ---->
sub {
my ($all_ids,@list);
my $cat_id = '239';
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $link_db = $DB->table('Links','CatLinks','Category');
$link_db->select_options ("ORDER BY Add_Date DESC LIMIT 10");
my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', \@$all_ids);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
push @list, $link;
}

my $output;
foreach my $link (@list) {
# Set the category url
my $url = $DB->table('Category')->as_url($link->{'Full_Name'});
# Set the detailed_url
my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('lastop', $link);
}
return $output;
}

lastop.html:

<img border="0" src="<%build_images_url%>/ol/<%Operator_Logo%>"><br>
<%OL_Code%>
<br>

Last edited by:

reenee: Apr 21, 2003, 6:55 AM
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
Everything you need should be in the global above. Why not have a play around with it - sorry, I just don't feel like doing it at the moment.

The breakpoint will need to use the length of the list which is $#list instead of $total.
Quote Reply
Re: [afinlr] Lastlink by specific main category In reply to
what about something like:

Code:
sub {
my ($cat_id, $cat_count, $columns) = @_;
($cat_id) || return;
($cat_count) || $cat_count = 10;
($columns) || $columns = 1;

my ($all_ids,@list);

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

push @$all_ids, $cat_id;

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

$link_db->select_options ("ORDER BY Add_Date DESC LIMIT $cat_count");

my $condition = GT::SQL::Condition->new( 'isValidated','=','Yes','CategoryID', 'IN', \@$all_ids);

my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
push @list, $link;
}

my $breakpoint = int (($#list+1)/2) + ( (($#list+1) % 2) ? 1 : 0);
my $width = int (100 / $columns});
my $i = 0 ; ## a counter

my $output=qq~<table width="100%"><tr>~; ## we open the table, the row

foreach my $link (@list) {
$i++;
# Set the category url
my $url = $DB->table('Category')->as_url($link->{'Full_Name'});
# Set the detailed_url
my $detailed_url = "$CFG->{build_detail_url}/$link->{'LinkID'}$CFG->{build_extension}";
$output .= qq~<td width="$width%">~;
$output .= Links::SiteHTML::display ('lastop', $link);
$output .= qq~</td>~;

if !($i % $breakpoint) {
$output .= qq~</td>\n <TD width=$width%>~; ## we are still adding columns
} else { ## we need to start a new row
$output .= qq~</td>\n</tr>\n <TR>\n <TD width=$width%>~; ## we start a new row
$i = 0; ## we can reset $i or leave it alone.... we reset it so we can have it easier below
}

} ## end of the foreach link
## we now close the table

if ($i % $breakpoint) {
$output .= qq~</td>\n </tr>\n </table>\n~;
} else {
## we need to add enough cells to finish the table, or we'll break some browsers.
## $i has the integer value of the number of cells we've already added to the row.
## we need to add $breakpoint - $i more cells.
## we will be adding AT LEAST one more cell, or we would have passed the if test above.
$output .= qq~</td>~;
for ($z = 0; $z < ($breakpoint - $i); $z++) { $output .= qq~<TD></TD>~ };
$output .= qq~ </tr>\n <\table>\n ~;
}
return $output;
}

THIS IS COMPLETELY UNTESTED and I'm not inclined to set up to test it. Use at your own risk <G>



PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Lastlink by specific main category In reply to
Hi Pugdoq, It was an error:

A fatal error has occured:

Can't modify logical or (||) in scalar assignment at (eval 401) line 4, at EOF
syntax error at (eval 401) line 25, at EOF
Global symbol "@list" requires explicit package name at (eval 401) line 30.
Global symbol "$width" requires explicit package name at (eval 401) line 36.
syntax error at (eval 401) line 40, near "if !"
Global symbol "$breakpoint" requires explicit package name at (eval 401) line 40.
Global symbol "$width" requires explicit package name at (eval 401) line 41.
syntax error at (eval 401) line 42, near "## we are still adding columns
} else"
Global symbol "$width" requires explicit package name at (eval 401) line 43.
syntax error at (eval 401) line 45, near "; ## we can reset $i or leave it alone.... we reset it so we can have it easier below
}"
(eval 401) has too many errors.

Please enable debugging in setup for more details.

A fatal error has occured:

GT::Config (11234): Unable to compile 'lastop' in file '/home/username/public_html/ringtones/cgi-bin/admin/templates/default/globals.txt': Can't modify logical or (||) in scalar assignment at (eval 401) line 4, at EOF
syntax error at (eval 401) line 25, at EOF
Global symbol "@list" requires explicit package name at (eval 401) line 30.
Global symbol "$width" requires explicit package name at (eval 401) line 36.
syntax error at (eval 401) line 40, near "if !"
Global symbol "$breakpoint" requires explicit package name at (eval 401) line 40.
Global symbol "$width" requires explicit package name at (eval 401) line 41.
syntax error at (eval 401) line 42, near "## we are still adding columns
} else"
Global symbol "$width" requires explicit package name at (eval 401) line 43.
syntax error at (eval 401) line 45, near "; ## we can reset $i or leave it alone.... we reset it so we can have it easier below
}"
(eval 401) has too many errors.


Please help and thank you so much
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
Ooops

Sorry. Wrong thread.

As I said, it was untested <G>

you need to start swatting bugs where the first error appears. I can't run this, so I'm sort of stuck looking at the code.


I can start you off with:

$cat_count ||= 10;
$columns ||= 1;



PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Apr 22, 2003, 2:26 AM
Quote Reply
Re: [reenee] Lastlink by specific main category In reply to
Try this:
Code:
($cat_count) || ($cat_count = 10);
($columns) || ($columns = 1);

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