Create a category
Create arcticle inside created category
Create 2 menu elements (blog-1 and blog-2) of type Category Blog linked both to same category
When you visit a article of menu element blog 1, the url must be index.php/blog-1/the-article-title
When you visit a article of menu element blog 2, the url must be index.php/blog-2/the-article-title
This works like this in Joomla 3
When you visit a article of menu element blog 1, the url is index.php/blog-1/the-article-title -> IT IS CORRECT
When you visit a article of menu element blog 2, the url is index.php/blog-1/the-article-title -> IT IS WRONG
Joomla 4.1.0, Apache 2.4, PHP 7.4.20
This was not a problem in Joomla 3. In Joomla 4 apparently what is happening is that the Router looks for the first menu item bound to the category, when it should look for the current menu item bound to the category.
Labels |
Added:
No Code Attached Yet
|
Title |
|
No, this is expected behavior. We don't want duplicate content.
more or less yes.
@leoalv try to obtaining two different urls that point to the same article, it's wrong from SEO and UX perspective.
Maybe you have to do this "duplication" with an alias. Or you have to rethink your "sitemap",
Remember that a blog can have a "strict" categories structure but if you want to do "multiple" assignments (like your example) you can use tags (very sparingly!).
I know this is DUPLICATE content, or not too, as far as I know to determine the duplicate content is considered the url and the content, not just the url, or am I wrong.
We know that Joomla articles are not for simple blogs, with the advent of custom fields a lot can be created. In this case I have created an override to blog.xml called features.xml with which it creates the blog-2 menu that shows data only from custom fields and in the blog-1 menu of the Category Blog type traditional data from one article and only 2 custom field data that is also displayed in blog-2, hence the need to have a single article instead of duplicates.
The creation of these 2 menu elements linked to the same category when both are of type blog (blog.xml) makes the links to the articles being in blog-2 have blog-1 as the parent menu element. But when I create 1 Features menu item (features.xml) and another of type blog (blog.xml), it doesn't matter if I create the menu item of type Features first or after the type blog, all links to the article in either of the elements have as parent the one of type blog. This in Joomla 3 works perfect, without these Joomla 4 problems.
I know that preventing duplicate content is a nice Joomla feature, but having the router look up the ID of the current menu item to build the links is too. Then:
Which one are we left with?
Which benefits the community more?
What is the correct way to request the menu IDs from the database to build the links? the first linked to the category or the current linked to the category?
I understand that you have implemented it in a way that worked for you in J3, but it did so by exploiting a bug in the system. J4 fixed this bug and I can say with a very high degree of certainty that we wont change this back again. The nice thing with J4 is, that you can override among other things this code, extend it, replace it entirely. So you can code the behavior which best suites you. But for the default, this is what we will stick with.
I understand that you have implemented it in a way that worked for you in J3, but it did so by exploiting a bug in the system. J4 fixed this bug and I can say with a very high degree of certainty that we wont change this back again. The nice thing with J4 is, that you can override among other things this code, extend it, replace it entirely. So you can code the behavior which best suites you. But for the default, this is what we will stick with.
Correct
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-03-17 22:31:41 |
Closed_By | ⇒ | bembelimen |
Ok, I'll close this, although I still think it's better to use the ID of the current menu item to build the links
Here I have some 3.x code to adjust the router to your liking, could be used with a plugin. I think the 4.x should work similar:
$router = Factory::getApplication()->getRouter();
$contentRouter = $router->getComponentRouter('com_content');
$rule = new class($contentRouter) implements RulesInterface
{
protected $router;
public function __construct(RouterView $router)
{
$this->router = $router;
}
public function build(&$query, &$segments): void
{
}
public function parse(&$segments, &$vars): void
{
}
public function preprocess(&$query): void
{
/*
Here we need at the end an Itemid to push into $query
Helpful stuff:
$menu = $this->router->menu;
$active = $menu->getActive();
$component = ComponentHelper::getComponent('com_' . $this->router->getName());
$views = $this->router->getViews();
$attributes = array('component_id');
$values = array((int) $component->id);
$attributes[] = 'language';
$values[] = array($language, '*');
$items = $this->router->menu->getItems($attributes, $values);
*/
}
};
$contentRouter->attachRule($rule);
Probably it's easier with 4.x but this should give you a start.
Here I have some 3.x code to adjust the router to your liking, could be used with a plugin. I think the 4.x should work similar:
@bembelimen Thanks for the help and the intention to help.
@richard67 @Hackwar @simbus82 To all those who have participated in this topic I will give you an example of using the Joomla core that is not duplicate content and without overrides, this case comes because in previous messages they recommended using tags.
I have a category, with items that are tagged with 2 tags (creaitve, branding), so I create 2 creative and branding menu items linked to the same category and filtered by tags. this with the current router will give me the following URLS for the articles:
/creative/creative-article-title-tagged-with-creative-tag
/creative/branding-article-title-tagged-with-branding-tag
when the correct urls should be:
/creative/creative-article-title-tagged-with-creative-tag
/branding/branding-article-title-tagged-with-branding-tag
think about it ...
Uhm, menu items are "more powerful" than categories. I think you have "mixed" the concepts of categories, menu items (aka URL) and tags.
I need to see your website to understand why your are doing this. Maybe a good structure to use in your case is:
/blog/tags/creative/creative-article-title-tagged-with-creative-tag
/blog/tags/branding/branding-article-title-tagged-with-branding-tag
where the only category is Blog and tags are "creative, branding".
You can "hide/morph" /tags/ by creating a menu voice for "tags" with an alias of your choice, so you can manage the url structure as you want starting from the tags tree.
Don't use tag-filtered menu items for these things. Create a rigid tree, the tags (in a good project) are chosen in advance, so you can create your own tags tree.
@Hackwar What do you think? Bug?