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

How to list/display of Sub Categories for any Detail Page.

Quote Reply
How to list/display of Sub Categories for any Detail Page.
Current category structure:

Texas
.... Dallas
.... Austin
....... ..... Austin_Link.1
....... ..... Austin_Link.2

Florida
.... Orlando
....... ..... Orlando_Link.1
....... ..... Orlando_Link.2
.... Miami
....... ..... Miami_Link.1


On Detail page I see that I can use:
<%title_loop.2.Name%>
<%title_loop.2.URL%>

& Using above on Detailed page I can display Name & URL of the category the listing is. However, is there a way to display list of all sub-categories (of main parent category) on detailed page?

So on detail page for "Austin_Link.1", it would display something like:
.... Dallas
.... Austin

While for detailed page of 'Miami_Link.1' it would show:
.... Orlando
.... Miami

So can this be done via global? that would allow me to include loop of category names & display info from subcategory_style2.html (similar to subcategory, however it would have different html/css style, as it is being used differently).

Thank you.

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] How to list/display of Sub Categories for any Detail Page. In reply to
Hi,

Untested, but give this a go:

Code:
sub {
# first work out the category this link is in. If its in multiple cats, we just grab the first one
my $cat_id = $DB->table("CatLinks")->do_query(qq|SELECT CategoryID FROM glinks_CatLinks WHERE LinkID = $_[0]|)->fetchrow || '';
if ($cat_id > 0) {
my $father_id = $DB->table("Category")->select( ['FatherID'], { ID => $cat_id } )->fetchrow || '';
my $sth = $DB->table("Category")->select( { FatherID => $father_id } );

my @cats;
while (my $catid = $sth->fetchrow) {
my $cat = $DB->table('Category')->select( { ID => $catid } )->fetchrow_hashref;

$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $cat->{Full_Name} ) . "/" . $CFG->{build_index};

push @cats, $cat;
}
}

return { parent_cat_loop => \@cats };
}

Call with:

Code:
<%global_name($ID)%>
<%loop parent_cat_loop%>
<a href="<%URL%>"><%Name%></a>
<%endloop%>

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] How to list/display of Sub Categories for any Detail Page. In reply to
Just tried it by am getting an error :(


Code:
Unable to compile 'cat_on_detail_page': Global symbol "@cats" requires explicit package name at (eval 53) line 18.

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] How to list/display of Sub Categories for any Detail Page. In reply to
Ooops, try:

Code:
sub {
# first work out the category this link is in. If its in multiple cats, we just grab the first one
my $cat_id = $DB->table("CatLinks")->do_query(qq|SELECT CategoryID FROM glinks_CatLinks WHERE LinkID = $_[0]|)->fetchrow || '';
if ($cat_id > 0) {
my $father_id = $DB->table("Category")->select( ['FatherID'], { ID => $cat_id } )->fetchrow || '';
my $sth = $DB->table("Category")->select( { FatherID => $father_id } ) || die $GT::SQL::error;

my @cats;
while (my $cat = $sth->fetchrow_hashref) {

$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $cat->{Full_Name} ) . "/" . $CFG->{build_index};

push @cats, $cat;
}

return { parent_cat_loop => \@cats };
}


}

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!

Last edited by:

Andy: Jan 8, 2020, 12:04 AM
Quote Reply
Re: [Andy] How to list/display of Sub Categories for any Detail Page. In reply to
Everything on the page is loading fine, however the global is not producing any output.

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] How to list/display of Sub Categories for any Detail Page. In reply to
Hi,

Try the modified version above

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] How to list/display of Sub Categories for any Detail Page. In reply to
Perfect it works :)

I even added:

<%if Direct_Links >= '70'%>
<a href="<%escape_html URL%>" class="btn list-group-item-action categories1 pad-minus-010"><%Name%></a> <%Direct_Links%>
<%endif%>

As I wanted to see if I can limit display of sub-category based on number of links & it works :)


Thanks Andy !!!

Vishal
-------------------------------------------------------