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
-------------------------------------------------------
Quote Reply
Re: [Andy] How to list/display of Sub Categories for any Detail Page. In reply to
Andy wrote:
Hi,

Try the modified version above

Cheers

Hey Andy,

Right now I am using this global:

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 };
}


}

This displays category names as desired on the Detailed page. However, it does not show other category names on the Category page.

i.e. For example on the Dallas Category page, I am thinking of showing below in the sidebar:
-----------------------------
Near-by Popular Locations:
Austin
Houston
San Antonio
El Paso
-----------------------------

In this example: along with Dallas, Austin, Houston, San Antonia, El Paso, categories are part of 'Texas' Sub-categories. (i.e. for the State of Florida, it would show near-by locations based in Sub Categories in Florida & so on for other states)


Any idea how can this work?

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

It won't work on category pages - as its looking for LinkID. I'm not too sure what you are trying to achieve 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] How to list/display of Sub Categories for any Detail Page. In reply to
Current category structure:

Texas
.... Dallas
.... Austin
....... ..... Austin_Link.1
....... ..... Austin_Link.2
El Paso
Fort Wort
Houston
San Antonio

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

----------------------------------------------
What I am trying to do:

On 'Dallas Category Page' : https://findpersonalinjurylawyer.com/...llas%2Findex.php;d=1 , on the sidebar, I want to display list of other categories from it's parent category 'Texas' (https://findpersonalinjurylawyer.com/...exas%2Findex.php;d=1).

Eventually there will be about 90 to 100 sub-categories in Texas, however ideally I want to display only top 10 to 15 of these sub-categories next to Dallas under the title Popular Locations in Texas'.

Using the above global from you, I am able to do so, but it works only on the detailed page, while I also want to be able to show this info on the category page (Example: https://findpersonalinjurylawyer.com/...llas%2Findex.php;d=1 )

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] How to list/display of Sub Categories for any Detail Page. In reply to
Ah ok - thats pretty simple then. The other global won't work, but its easy to change it specifically for this task:

get_parent_categories

Code:
sub {

my $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) {

next if $cat->{ID} == $cat_id;

$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 };


}

Then call with:

Code:
<%get_parent_categories($ID)%>
<%loop parent_cat_loop %>
....
<%endloop%>

Untested, but should work :)

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

Thanks a lot Andy.. Smile Smile

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