1

Joomla 3.9.12, JoomGallery 3.4

I have a site with joomShopping for e-shop and JoomGallery for portfolio. The site has 2 menus where some menu items of the first are menu item aliases of the second.

Menu structure is

- Home
- Shop(JoomShopping component)
- - Many subcategories
- Portfolio (JoomGallery component) (Gallery view)
- - Portfolio price range 1 (Categories view)
- - Portfolio price range 2
- - Portfolio price range 3
- - Portfolio price range 4
- Other pages

In portfolio categories are subcategories like Portfolio Item 1 (Category view). For ex., Portfolio Item 1 placed in Price range 1.

For better and easier re-linking of products with portfolio items, I made a content plugin like JoomImages which inserts a category thumb (1st image in category or from category settings or by 'imgid' param), title and category description and wraps this in a link to the category.

All works fine except the link construction.

1st way - use JoomGallery's $this->_interface->route():

$catlink = $this->_interface->route('index.php?&option=com_joomgallery&view=category&catid=' . $catid);

If I set $catid as Protfolio item 1 id, I should get a sef url like this in menus:

site.ru/portfolio/price-range-1/portfolio-item-1/
// fine in all menus and sef url is true

However, in my plugin, I got sef url like this:

site.ru/portfolio/price-range-3/portfolio-item-1/
// incorrect -----^^^^^^^^^^^^^

2nd way - use Joomla JRoute::_():

$catlink = JRoute::_('index.php?&option=com_joomgallery&view=category&catid=' . $catid);

With this, I generate SEF urls like:

site.ru/component/joomgallery/portfolio-item-1

I understand that I must set an Itemid in the url for rewriting, but how to get it?

function getItemid( $component, $view )
{
    $items = JFactory::getApplication()->getMenu( 'site' )->getItems( 'component', $component );
    foreach ( $items as $item ) {
        if($item->query['view'] === $view){
            return $item->id;
        }
    }
}

From this function, I got an Itemid of Joomgallery's top level menu item - Portfolio.

How do I get site.ru/portfolio/price-range-1/portfolio-itme-1 ?

  • Welcome to JSE. I have needed to delete a couple of your posts... one for being Not An Answer and one for being non-English. Please take the tour while you wait for volunteers to respond to your questions. – mickmackusa Oct 25 at 16:19
0

I came to the conclusion that it is need to specify menu itemid as a parameter. If the menu has only one item associated with JoomGallery, then it can be obtained automatically. If several, then it is necessary to specify force in shortcode params. For example, plugin shortcode now is {jgcat catid=123 itemid=194 tmpl=bootstrap4}.

Then php code parses plugin shortcode and builds url by JRoute. I use JoomGallery interface for this.

$this->_interface = new JoomInterface();
$this->_interface->getPageHeader();
if ($params['itemid'] != "") { //params array
    $ItemId = $params["itemid"];            
} else {
    $ItemId = $defaultJoomGalleryItemId;//we got it above
}
$catlink = "index.php?&option=com_joomgallery&Itemid=".$ItemId."&view=category&catid=".$catid;
$catlink = $this->_interface->route($catlink);

So, if you have only 1 JoomGallery menu item you can do nothing, plugin will get item id automatically. If you have more - you must to set it for good sef-links.

  • Can you please share the exact adjustments that you made to your code? Many Joomla users do not yet have the experience/expertise that you have -- please do your best to explain how to implement your solution and why you feel it is a good technique. Generously sharing your insights through clear questions and educational answers is a great way to empower others as well as earn privilege-unlocking rep points. (When the Stack Exchange software permits it, you will be able to accept your own answer to mark this page as resolved.) – mickmackusa Oct 26 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.