Categories view link to categories with existing menu item
-
adamgatt
- Phoca Newbie

- Posts: 5
- Joined: 19 Feb 2016, 03:01
Categories view link to categories with existing menu item
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.
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.
- Jan
- Phoca Hero

- Posts: 49144
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Categories view link to categories with existing menu it
Hi, try to see:
https://www.phoca.cz/documents/16-joomla ... -in-joomla
and the similar articles (at the bottom)
Jan
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

- Posts: 5
- Joined: 19 Feb 2016, 03:01
Re: Categories view link to categories with existing menu it
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?
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?
- Jan
- Phoca Hero

- Posts: 49144
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Categories view link to categories with existing menu it
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.
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
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.
Jan
If you find Phoca extensions useful, please support the project
-
adamgatt
- Phoca Newbie

- Posts: 5
- Joined: 19 Feb 2016, 03:01
Re: Categories view link to categories with existing menu it
Thanks Jan.
I now understand.

I now understand.
- Jan
- Phoca Hero

- Posts: 49144
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Categories view link to categories with existing menu it
Ok
If you find Phoca extensions useful, please support the project
-
adamgatt
- Phoca Newbie

- Posts: 5
- Joined: 19 Feb 2016, 03:01
Re: Categories view link to categories with existing menu item
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:
I added the below:
And then replaced all with
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.
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){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
}
Code: Select all
$cv->linkCode: Select all
$galleryURL- Jan
- Phoca Hero

- Posts: 49144
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Categories view link to categories with existing menu item
Hi, Ok, thank you for the info, in which version of Phoca Gallery did you test it?
Jan
Jan
If you find Phoca extensions useful, please support the project
-
adamgatt
- Phoca Newbie

- Posts: 5
- Joined: 19 Feb 2016, 03:01
Re: Categories view link to categories with existing menu item
Hi Jan.
I am using Version 4.2.2
I am using Version 4.2.2
-
christine
- Phoca Hero

- Posts: 2938
- Joined: 28 Nov 2010, 17:20
Re: Categories view link to categories with existing menu item
Hi,
current version is: PG 4.3.1. https://www.phoca.cz/download/category/1 ... -component
https://www.phoca.cz/news/893-phoca-gall ... 1-released
Kind regards, Christine
current version is: PG 4.3.1. https://www.phoca.cz/download/category/1 ... -component
https://www.phoca.cz/news/893-phoca-gall ... 1-released
Kind regards, Christine