ADBLOCK_MSG
The structure of internal links within Joomla sitePublished: Saturday, 14 June 2014 14:00 Written by Ogri Hits: 14340
Joomla Internal Links and examples of their usage :: CONTENT
The structure of internal links within Joomla site
Content filtering by articles, categories and components
Unified filtering of mod_jcomments_latest module's output
end faq
Recently I wrote and implemented several functions that allow you to filter the pages output of the website running CMS Joomla version 2.5 and later. Before sharing them with the public, I will touch on the subject posed in the title of this article, as the principle of formation of internal links to Joomla application pages will help to better understand their algorithms.
A bit of theory
Applications for the CMS Joomla are being developed as components. Components are responsible for the pages output. A link to each page is generated in the respective component in the standard URI format:
http://[site name]/index.php?[query string]
The query string is a sequence of key=value
pairs separated by an ampersand. Keys' values just determine the output of each page. URI of pages are generated in accordance with the structure of the component. Currently we are not interested in the mechanism of these links formation, but the result for each page or group of pages of the application will be important. Knowing how to identify keys and their values, you can flexibly operate on the output of the page content.
My only comment is that you'll see a link in the above format in the address bar of your browser only if the SEF is off on your site. When the SEF is on, the router converts page addresses into a more intelligible appearance for the human perception. But we interested in those internal links, so to get the keys and values from the address bar, you can disable SEF on the test site.
Joomla framework assigns a number of standard keys. Consider the most used ones.
- option - the component name with the prefix
'com_'
; - view - appearance of a particular component page;
- layout - additional variant of the output of a particular view;
- Itemid - identifier of a menu item, which is bound to a page, if binding occurs.
- lang - the webpage language.
In the case of multilingual site another parameter is also added
Component developers can add keys used to build the page addresses of each particular application. For example, a basic Joomla component com_content
, which is forming the structure of categories and articles, operates with the following additional keys:
- id - Identifier of article or category depending on the current view. It takes the value of the article ID in case of an article page output (
view=article
). The key contains a value of category ID when listing categories (view=categories
) or articles in the form of category list or blog (view=category
); - catid - Identifier of a category, which related to the current article (
view=article
).
Key values for this component:
- option -
com_content.
- view -
archive
- archived articles;article
- an article;categories
- a list of categories;category
- articles in a category presented as list or blog;featured
- featured articles in the form of a blog;form
- form of creating or editing an article content.
- layout -
blog
- withdrawal of articles in a category in the form of a blog in the category presentation (view=category);edit
- option for the form of creating or editing the article (view=form
). There are alsopagebreak
andmodal
. It is unlikely that any of them is useful in practice. Maybe the first one, and even then only for the convenience of users having privilege to edit content.
- lang - appears in the page URI of the multilingual Joomla website and contains two-lettered identifier of the active language, corresponding to the parameter URL Language Code in the admin panel's language settings - eg:
en
,ru
. (Languages and their settings mentioned, for example, in an article about the 404 page customization.) - Itemid, id, and catid - take values of identifiers according to the content page's view type; wherein the first one always contains the menu item ID in the numeric format, while the other two in a specific context can be in the following form:
[ID]:[alias]
. It will yet be discussed further on.
Examples of page output of the component com_content
Consider a few examples of the query string keys and their values in URIs of some specific pages generated by the com_content
application.
Example 1.
On a page bound to the menu item 35, the blog of featured articles of English part of the site is displayed:
option=com_content&view=featured&Itemid=35&lang=en
Example 2.
Articles of a category with id=27 are displayed in the form of a blog on the Russian part of the site. The menu item, which is linked to the page is 62:
option=com_content&view=category&layout=blog&id=27&Itemid=62&lang=ru
If there was no pair of
layout=blog
, hen the articles would be displayed by default as a list of their titles.Example 3.
Page of the article that you are now reading:
option=com_content&view=article&id=813:struktura-vnutrennikh-ssylok-sajta-na-joomla&catid=27:stroim-sajty&Itemid=62&lang=ru
The last example just illustrates the case where the article and the category IDs also contain aliases, separated by a colon from ID in numerical representation. In the section about the use of query string keys will be examined, how to handle them.
So, by disabling SEF on your test site, you can see the parameters of any page in the address bar of your browser.
Practical usage
If you had enough patience to overcome the previous sections, congratulations: it's time to discuss, how to utilize received information.
Knowledge of query parameters allows you to compose a condition for some code execution on one or more specific pages and page group, united by a common feature - component, category or language.
To create such conditions let's use the structure:
$value = JFactory::getApplication()->input->getCmd([key]);
in which for [key]
we will substitute the string names of the parameters we need. Method getCmd
returns a key value as a string. For instance, the condition for pages relating to articles and categories of the com_content
component will be the following:
$option = JFactory::getApplication()->input->getCmd('option'); if ($option == 'com_content') { ... }
For integer identifiers the method getInt
can be used:
$Itemid = JFactory::getApplication()->input->getInt('Itemid'); if ($Itemid == 1) { ... }
The only hitch occurs in the above mentioned case where IDs can be followed by a colon and the alias. Although these tails are being added to ID only when SEF is turned off, such cases are to be treated: what if you will need to disable SEF? We need a universal solution. Therefore, the condition for articles and categories will be a little more complicated:
$temp = explode(':', $jinput->getCmd('id')); $article_id = $temp[0] + 0;
(This approach has already been considered in articles about hiding breadcrumbs on certain pages and selective output of social media buttons.)
Now we can create a block of code for initializing of all the variables that correspond to component's request keys:
$jinput = JFactory::getApplication()->input; $option = $jinput->getCmd('option'); $lang = $jinput->getCmd('lang'); $view = $jinput->getCmd('view'); $layout = $jinput->getCmd('layout'); $Itemid = $jinput->getInt('Itemid'); $temp = explode(':', $jinput->getCmd('id')); $art_cat_id = $temp[0] + 0; $temp = explode(':', $jinput->getCmd('catid')); $cat_id = $temp[0] + 0;
After receiving the parameter values of the page output, you can combine them to create conditions for the content filtering. The functions mentioned in the beginning of this article, contain such conditions.
In conclusion - a few comments. Those who use additional frameworks like K2, T3, etc. - can get keys provided by their developers, on the same principle. As, however, of any other components. Those who want to create their own original components on the basis of existing ones or from scratch, can read online about the MVC (Model-View-Controller) pattern, examine the JRoute
method and other intricacies. And the last thing I would like to note: customizing is great, but you should insert your own code into the core and extensions very carefully, trying to minimize the process of restoring your changes after you installed updates.
Latest News
-
Tuesday, 21 July 2020 03:18
Joomla 3: Redirect to same page after successful login -
Saturday, 30 December 2017 16:11
Joomla: how to add your own language constants or override existing ones -
Thursday, 30 November 2017 23:27
Joomla: Integrate reCAPTCHA v2 (NO CAPTCHA) into JComments -
Saturday, 25 June 2016 15:33
Unified filtering of mod_jcomments_latest module's output -
Thursday, 17 September 2015 16:23
Post an illustrated Joomla-site article on Facebook using OG-tags
Articles Most Read
-
148974
Migrating from Joomla 1.5 to Joomla 2.5. Part 2-1. Transferring jDownloads and jComments -
83761
Joomla: Integrate reCAPTCHA v2 (NO CAPTCHA) into JComments -
57199
Migrating from Joomla 1.5 to Joomla 2.5. Part 2-2. Template, editor, and other extensions -
40161
Editing animated GIF-images in Photoshop CS3 -
39327
Custom 404 error page in Joomla 2.5
Login
Guest Column
Recent comments
-
Custom 404 error page in Joomla 2.5
- Roseann 02.11.2020 08:17
-
Joomla: Integrate reCAPTCHA v2 (NO CAPTCHA) into JComments
-
PG SLOT
13.01.2021 09:21
Hey! I could have sworn I've been to this site before but after browsing through some of the post ...
-
Nidia
12.12.2020 08:04
HELP. I can't write a comment without it hanging.
-
Launa
17.11.2020 15:13
I can agree with the accuracy of this as I work in a related sector. Interesting cheers for sharing.
-
JD sports vouchers
04.10.2020 03:12
Happy to pay for something like this, or donate witth paypal even
-
PG SLOT
13.01.2021 09:21
-
Joomla: how to add your own language constants or override existing ones
-
Vouchersort
29.10.2020 11:33
Is this a free template that you are using as I really love it. As a website desugner myself I hope that ...
-
Vouchersort
29.10.2020 11:33
-
Migrating from Joomla 1.5 to Joomla 2.5. Epilogue
-
Dewitt
11.02.2021 06:17
HELP. I can't write a comment without the page freezing.
-
Dewitt
11.02.2021 06:17
-
Migrating from Joomla 1.5 to Joomla 2.5. Part 2-1. Transferring jDownloads and jComments
-
Francine
14.12.2020 08:49
I cant stomach this person so sorry x
-
Vouchersort
30.10.2020 15:43
Once again, great resource for us newbs.
-
Francine
14.12.2020 08:49
-
Unified filtering of mod_jcomments_latest module's output
-
Фильмы 2022 онлайн
03.12.2021 21:37
This web site definitely has all of the info I wanted about this subject and didn't know who to ask.
-
Фильмы 2022 онлайн
03.12.2021 21:37
Read more...