Categories view link to categories with existing menu item

Phoca Gallery - image gallery extension
adamgatt
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 19 Feb 2016, 03:01

Categories view link to categories with existing menu item

Post by adamgatt »

Hello.

Thanks for this great component!

I've got some categories (name, othername) that I am showing with their own category view menu items. They have URLs of 'domain.com/product/name/gallery', 'domain.com/product/othername/gallery'. I also have some categories that do not have a category view menu item.

I also have a categories menu item, and on categories menu item page the link to a category with an existing menu item (as above) does not show the same link as above, but rather it adds '/category/id-name', '/category/id-othername' to the end of the link. I'd like to stop this from happening to eliminate duplicate URLs.

I've attempted with a template override in categories/default_categories.php

I looked at the Link on the menu item (in the Joomla Admin CP) of one of the categories above which has URL of 'domain.com/product/name/gallery'' and it's Link is 'index.php?option=com_phocagallery&view=category&id=1'.

I looked at the raw URL in $cv->link in the view. For categories with an existing menu item (as above) it is 'index.php?option=com_phocagallery&view=category&id=1:name&Itemid=181'. For categories without a menu item it is 'index.php?option=com_phocagallery&view=category&id=1:name'

I have used string manipulation to strip the ':name&Itemid=181' off the end of the URL (if Itemid parameter exists) to make the URL match exactly the same as the Link found on the menu item in the Joomla Admin CP. I thought that this would link the categories with existing menu items to the same URL as the menu item, however it does not.

Can anyone explain why this does not work?

Thanks for any advice.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49144
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Categories view link to categories with existing menu it

Post by Jan »

Hi, try to see:
https://www.phoca.cz/documents/16-joomla ... -in-joomla

and the similar articles (at the bottom)

Jan
If you find Phoca extensions useful, please support the project
adamgatt
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 19 Feb 2016, 03:01

Re: Categories view link to categories with existing menu it

Post by adamgatt »

Hi Jan.

Thanks for taking the time to respond. I had read those articles before I attempted the template override but unfortunately I can't fully follow their logic and they mention modules and plugins (I'm only using the Phoca Gallery component here).

Is what I am trying to achieve not possible? i.e if a menu item exists for a category, make the categories view link the category to that same menu item URL without adding /category/id-name to the end?
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49144
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Categories view link to categories with existing menu it

Post by Jan »

Hi, the system needs to get information about sites you want to visit.

You can create a menu link called "abc" but you need other parameters too, because when you will access "abc?id=1", Joomla! system could know, it is Phoca Gallery, because the alias "abc" is assigned to Phoca Gallery menu link, and it knows, the ID is 1 BUT !!! which ID. Is this ID of category or it is ID of image.

This is why you need the identifier in the URL "category|categories|detail", etc. :idea: Without this identifier the Joomla! system will not know which view it should display - if it should display category with ID = 1 or image with ID = 1.

Jan
If you find Phoca extensions useful, please support the project
adamgatt
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 19 Feb 2016, 03:01

Re: Categories view link to categories with existing menu it

Post by adamgatt »

Thanks Jan.

I now understand. :D :oops:
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49144
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Categories view link to categories with existing menu it

Post by Jan »

Ok
If you find Phoca extensions useful, please support the project
adamgatt
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 19 Feb 2016, 03:01

Re: Categories view link to categories with existing menu item

Post by adamgatt »

Hi Jan.

I know I am going back a while but I just revisited this problem I was having and managed to get something working. I am putting here for the benefits of others that might face the same problem!

In the components/com_phocagallery/views/categories/tmpl/default_categories.php file

After the line:

Code: Select all

foreach ($this->categories as $ck => $cv){
I added the below:

Code: Select all

$galleryURL = $cv->link;
	
	if (strpos($galleryURL, 'Itemid') !== false) {
		
		//There is an existing link... Cut the end of it off...
		//It looks like index.php?option=com_phocagallery&view=category&id=1:adam at the moment. Cut the :adam off..
		
		$trimmedURL = substr($galleryURL, 0, strpos($galleryURL, ":"));
		
		//Find the menu item with the link!!!!
		$db = JFactory::getDBO();
		$queryMenuAlias = "SELECT path FROM #__menu WHERE link = '" . $trimmedURL . "' AND published = 1";
		$db->setQuery($queryMenuAlias);
		$resultMenuAlias = $db->query();
		
		if(mysql_num_rows($resultMenuAlias) > 0) {
		
			while($rowMenuAlias = mysql_fetch_array($resultMenuAlias)) {
				
				$galleryURL = $rowMenuAlias['path'];
			}
		}
		else {
		//Do nothing as there is no active menu to point to
		}
	}
	else {
		//Do nothing as there is no active menu to point to
	}
And then replaced all

Code: Select all

$cv->link
with

Code: Select all

$galleryURL
This will direct the href to an existing menu item for the category if it already exists, and if it doesn't it will do nothing.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49144
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Categories view link to categories with existing menu item

Post by Jan »

Hi, Ok, thank you for the info, in which version of Phoca Gallery did you test it?

Jan
If you find Phoca extensions useful, please support the project
adamgatt
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 19 Feb 2016, 03:01

Re: Categories view link to categories with existing menu item

Post by adamgatt »

Hi Jan.

I am using Version 4.2.2
Post Reply