Joomla get article nice URL - php

I am new to Joomla and am trying to develop a module under 3.1. I managed to get the selected article ID and title in the module options but I don't know how to get the url to the ID, something similar to get_permalink(ID) in Wordpress.

You would want to run the url through JRoute to get the full url. You would also need to know how Joomla articles are usually built.
$url = JRoute::_('index.php?option=com_content&view=article&id='.$id);
This assumes that you have the id in the variable $id. For the rest of the url you would need to know the component you are calling (added as the option like above, Content manager is always com_content) and the view (which for an article is article). You can see the different views available for com_content by checking the file structure under /components/com_content/views/. Besides Article, you should see articles, categories, and category as well as a few other.

Related

Joomla custom component customizations

I needed a component for specific catalog, so I've paid for it to one freelancer. As it turned out, he's not very good at his job and I was given a component that works only partly. The biggest issues are router, breadcrumbs and json array for parent categories.
1. Router
currently it shows only domain.com/menuitem/viewname?id=X. There are 4 different views that looks like are not connected at all. in db, every view has its own table as it was requested, important fields are as follows:
Main Categories (root):
id, name, alias
General Categories:
id, name, alias, root_id
General Subcategories:
id, name, alias, cat_id
Detail:
id, name, alias, subcat_id[json array]
What I would like to do is to make SEF urls to look like this: domain.com/menuitem/root_alias/category_alias/subcategory_alias/detail_alias but I was told that it can't be done this way. I checked the SEF documentation on joomla portal but I can't figure it out (if it's even possible and if not, what would be a good SEO approach).
2. Breadcrumbs
Maybe it's caused by router and separate views, but they always show Home > Menuitem, but in mainmenu it's only /alias while in breadcrumbs it's /alias/mainview. I found how to add custom breadcrumbs into pathway on joomla portal, but I can't figure out how to get parent items. If there was a solution with SQL I could use it would be enough.
3. JSON array in db
I would like to change it to integer value and add new table subcategory_detail_xref so I can find items easily. Only way I can do it now is by using regular expression in SQL which I don't think is a good idea. I've checked tutorials on joomla portal but it looks just too complicated.
Any ideas, links to examples or tutorials that can help or solutions are highly appreciated.
PS: My website is running on latest Joomla (3.5) so if there are solutions only available for 3.5+ it's fine, I don't have any plans to downgrade
For router source code, you can refer to com_content, it's similar yours, in the 3.5 version, the router has to implement an interface.
There is no detail document at Joomla Developer site, com_content is exactly what you can learn to get it.
The breadcrumb you have to develop similar of router logic
Category table should extend the JNestedTable for multiple level tree structure

Redirect Joomla 3 component url to menu associated one

I have this SEO issues with Joomla, that Google Webmasters Tools catches as duplicate content, titles, description...
I have an article BABOONS with id 1, and is associated with sub-category Monkeys of parent category Animals. This parent and sub category are associated to menu items.
So, normally link to this article should be www.site.com/animals/monkeys/1-baboons
And here is the problem: If you try to access to this link trough component like this:
www.site.com/component/content/article/1-baboons
link still will be valid, and it will open this article but with no itemid associated! And, as its the same title, description, keywords and content, but different URL, google says that this is duplicate content.
I have tried many components for SEF url handling, but best case scenario was returning 404.
I have tried adding rel=canonical:
<link href="http://'.$_SERVER['SERVER_NAME'].JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)).'" rel="canonical" />
but with no luck, because it displays current url.
My question is, if there is any redirect technique or peace of code that will redirect component/content/article/1-baboons to its parent itemid /animals/monkeys/ that actually is associated with?
Did you try using the built in redirect component? It's not the ideal solution but it will work fine if it is just one. The link that you are showing is basically the permalink, guaranteed to be unique no matter what. The question is, what is it that is leading Google's spider to that link? Usually this happens when a module or plugin is not routing a url (i.e. wrapping in JRoute()). The core ones are generally good on this (though not unknown to find a mistake) but if you have anything that is generating links that you have installed that is probably where the issue is. You can look at any of the core articles modules and see what the code should look like.

Joomla 2.5 latest article from a category link

I would like to create a menu item with dynamic links to the latest article published in a given category.
I don't want to use the default category blog link because I want the link to leed straight to the article page and avoid duplicate content.
hope this is comprehensible, thx for helping me with this issue.
There are 2 ways to accomplish this, one with code, one without.
The no code method involves replacing the standard Joomla com_content with a CCK extension that has a latest item functionality built in - I know K2 has it for sure, there are likely others.
The other method would require you to create a new model/view/menu item that only pulls the latest published article. This would actually not be terribly difficult since you could basically copy most of the category model and use most of the article view to come up with what you need. The changes are a little too involved to post here however.

Joomla article pretty url that's not tied to a menu

I am working in Joomla 1.5 and have an article that I don't want listed in any of my menus. It is a special promotional page that exclusive people will be given the link to. Is there a way to give the article a pretty URL?
Currently the URL that works is /index.php?option=com_content&view=article&id=35. I would like that to be /15k.
Anyone help me?
I have seen this question, but the URL isn't quite what I'm looking for.
To get that URL you will need Joomla!'s SEF/SEO settings turned on (I'm assuming you've already got that setup).
In Joomla you have to create a new menu, call it something like "Utility Menu" but don't give it a "Module Title" - you don't want to display this menu so you don't need the module.
Then create a "Single Article" menu item with the alias 15k as a menu item within the "Utility Menu". You should now be able to access the article at the http://www.yoursite.com/15k
If you want to link to this from another menu create a menu item alias and point it at the 15k menu item. If you want to link from within an article simply point the link to the 15k menu item.
[Edit]
Routing in Joomla! first looks through the user defined paths (i.e. menu's and their menu items) then if it can't find a match for the requested resource that way it asks the particular component to build the route and if the components router is basic (i.e. nearly every single one in Joomla! 1.5) then you get the ?option=com_somecomponent&id=X style result. In 2.5 this is much improved but still uses the same routing mechanism.

URLs for Joomla Component

I have created a simple basic component in joomla named, careerform so I want to know that what will be its url? Will it be :
index.php/?option=com_careerform
or in sef it will be something like:
index.php/components/careerform
or it will be like this while using .htaccess
/careerform
Is it true or what are joomla default URLs with different settings? Please tell what you know.
thanks for your time.
While what you are asking to do is possible, it would be rather complicated to rename a component. As part of the renaming you would have to update the names of dozens if not hundreds of classes throughout every file of the component. Very likely to run into some bugs because of this.
The far easier prospect is to just avoid these types of urls in your site. Joomla will only fall back to that style of url if a menu item does not exist for the view. Because of that, you can make the url into this:
http://sitename.com/any-component-alias/
To do this, go into the menu manager and create a new menu item. If you don't want this as part of the main menu, you can create a new menu. (I typically have a menu called "Hidden" for menu items that I want aliased but don't actually link to throughout the site from a menu.) When creating the menu item, make sure the type matches the component and view. The alias will then be whatever is entered in the alias box just below the title.
The one issue you may run into with this is that a component may not have a menu type for a particular view. In that case, you you would need to add the necessary metadata.xml file to the view (which again would be much easier than renaming the component!). A good tutorial for that can be found here: http://docs.joomla.org/Adding_view_layout_configuration_parameters.
yes if SEF will be enabled then index.php/component/careerform will be used.
You can create custom URLs by developing a router for your component.
There is very good documentation for it here.

Categories