How to create material in joomla 2.5. Material in Joomla. Practice - Multiple circular linking of category materials

Materials

Let's start with a few definitions. Materials in Joomla! this is the information you want to display on the site. They typically consist of text, images, or other types of content. For many Joomla! Articles are the main content presented on the site.

It is important to understand that the material in Joomla! radically different from its final appearance on the site itself. For example, material can be designed in different fonts, colors, headings and backgrounds, and can be presented in different parts of the page itself.

Sections and categories

Sections and categories in Joomla! allow you, if desired, to organize the arrangement of your materials. Here's how it works. A section contains one or more categories to which materials can be assigned. One material can only be in one category and one section.

Let’s say there is a section called “Pets” and categories “Dogs” and “Cats”. We will attach materials about dogs to the “Dogs” category, and about cats to the “Cats” category. Thus, material about dogs will be located in the “Pets” section, in the “Dogs” category. The same material cannot be in different categories. To get around this nuance, you can create a new category “Cats and Dogs”, or create a new material to place it in the category you need.

Why use sections and categories?

There are two main reasons why you will want to organize your materials into categories and sections.

Blog and List Schemes

First of all, in Joomla! There are built-in menu options to take advantage of these features. Blogs section, lists section, blog categories and lists categories. These menu tabs allow you to easily display content that belongs to a specific section or category. As soon as a new material is created and defined in a category and section, it will be automatically placed on the page that you specified in the settings.

For example, you have a Blog Categories menu tab for the “Pets” category and you specify in the settings to show the newest materials at the beginning of the category. The next time you add new material, it will appear at the top of the list. You will not be required to take any action other than adding the material to the “Pets” category.

Organizing materials in the Material Manager

If you have a lot of content on your site, the second reason to use sections and categories is simply to organize them in a way that makes sense to you. For example, in the material manager you can filter material by category or section. With 200 articles on the site, you can easily find the one you need by remembering its category or section.

Sections, categories and menu organization

It is important to understand that if Joomla! uses the organization of materials into three levels (Section>Category>Material), the menu structure of your site will not necessarily depend on this. For example, your site may have one menu level, or it may have six.

Other category types

There is also the possibility of some confusion regarding the categories. Sections are used only for materials. However, categories are also used for components including banners, contacts, news feeds, and links. These categories are completely different from content categories and are displayed in other parts of the page in the user area of ​​Joomla!. So, if you come across the concept of categories, you may mean categories of materials, or categories of components.

You have no rights to post comments

What is he doing: Each material can be assigned several categories. When viewing the material, all categories in which the material is contained will be shown (although this is at your discretion, you may not show it). When viewing categories, naturally, there are no duplicates.

The hack requires changing both the database and several Joomla files, so make copies of them before editing the files.

Step 1- Run a script for the database, where # is the prefix of tables in your database. The best way to do this is through phpMyAdmin.

ALTER TABLE `#_content` ADD `catid2` INT (11) NOT NULL DEFAULT "0" AFTER `catid` ;
ALTER TABLE `#_content` ADD `catid3` INT (11) NOT NULL DEFAULT "0" AFTER `catid2` ;
ALTER TABLE `#_content` ADD INDEX (`catid2`);
ALTER TABLE `#_content` ADD INDEX (`catid3`);

Step 2- Adding the ability to specify several categories in the admin panel when creating/editing material
Editing the file administrator\components\com_content\views\article\tmpl\edit.php
Are looking for

form->getInput("catid"); ?>

Add after

form->getInput("catid2"); ?>form->getInput("catid3"); ?>

Editing the file administrator\components\com_content\models\forms\article.xml
Are looking for

label="JCATEGORY"
class="inputbox" required="true"
>

Add after


>

label="JCATEGORY" description="JFIELD_CATEGORY_DESC"
class="inputbox" required="false" default="0"
>

Step 3- we make it possible in the admin panel for materials linked to several categories in the Category column to show all categories to which the material is linked
Editing the file administrator\components\com_content\views\articles\tmpl\default.php
Are looking for

escape($item->category_title); ?>

and replace it with

escape($item->category_title);
if ($item->category_title2) echo "


".$this->escape($item->category_title2);
if ($item->category_title3) echo "
".$this->escape($item->category_title3);
?>

In the described option, the list of categories is displayed simply in a column. The division is made with a horizontal line for convenience. Convenient for a small number of categories, no more than 3.

Editing the file administrator\components\com_content\models\articles.php
Are looking for

// Join over the categories.
$query->select("c.title AS category_title");
$query->join("LEFT", "#__categories AS c ON c.id = a.catid");

and add after:


$query->
$query->
$query->
$query->

$query->where("c.lft >= ".(int) $lft);
$query->where("c.rgt<= ".(int) $rgt);

and replace it with

$query->where("(c.lft >= ".(int) $lft." AND c.rgt<= ".(int) $rgt.") OR (sister2.lft >= ".(int) $lft." AND sister2.rgt<= ".(int) $rgt.") OR (sister3.lft >= ".(int) $lft." AND sister3.rgt<= ".(int) $rgt.")");

Step 4- We teach Joomla to show when viewing a material all the categories to which this material is assigned.
Editing the file components\com_content\models\article.php
Are looking for

$query->select($this->getState(


"a.mask, a.catid, a.created, a.created_by, a.created_by_alias, " .

Replace with

$query->select($this->getState(
"item.select", "a.id, a.asset_id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, " .
// If badcats is not null, this means that the article is inside an unpublished category
// In this case, the state is set to 0 to indicate Unpublished (even if the article state is Published)
"CASE WHEN badcats.id is null THEN a.state ELSE 0 END AS state, " .
"a.mask, a.catid, a.catid2, a.catid3, a.created, a.created_by, a.created_by_alias, " .
// use created if modified is 0

// Join on category table.
$query->select("c.title AS category_title, c.alias AS category_alias, c.access AS category_access");
$query->join("LEFT", "#__categories AS c on c.id = a.catid");

Add after

// Join over the categories to get other category titles
$query->select("sister2.title as category_title2");
$query->join("LEFT", "#__categories as sister2 ON sister2.id = a.catid2");
$query->select("sister3.title as category_title3");
$query->join("LEFT", "#__categories as sister3 ON sister3.id = a.catid3");

Editing the file components\com_content\views\article\tmpl\default.php
Are looking for

$url = "item->catslug))."">".$title."";?>
get("link_category") and $this->item->catslug) : ?>


Replace with

$title2 = $this->escape($this->item->category_title2);
$title3 = $this->escape($this->item->category_title3);
$url = "item->catid)) . "">" . $title . "";
$url2 = "item->catid2)) . "">" . $title2 . "";
$url3 = "item->catid3)) . "">" . $title3 . "";
?>
get("link_category")) : ?>
if ($this->item->category_title2) echo ", ".$url2;
if ($this->item->category_title3) echo ", ".$url3;
?>

if ($this->item->category_title2) echo ", ".$title2;
if ($this->item->category_title3) echo ", ".$title3;

Note: the same operation with the default.php file must be done with the templates you use, if they have this file. For example, it contains the template beez5\html\com_content\article\default.php

Step 5- We teach Joomla to show when viewing a category all the categories to which materials are assigned.
Editing the file components\com_content\models\articles.php
find


$query->select(
$this->getState(
"list.select",

"a.catid, a.created, a.created_by, a.created_by_alias, " .

Replace with

// Select the required fields from the table.
$query->select(
$this->getState(
"list.select",
"a.id, a.title, a.alias, a.title_alias, a.introtext, " .
"a.checked_out, a.checked_out_time, " .
"a.catid, a.catid2, a.catid3, a.created, a.created_by, a.created_by_alias, " .

// Join over the categories to get parent category titles
$query->select("parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias");
$query->join("LEFT", "#__categories as parent ON parent.id = c.parent_id");

Add after

// Join over the categories to get other category titles
$query->select("sister2.title as category_title2");
$query->join("LEFT", "#__categories as sister2 ON sister2.id = a.catid2");
$query->select("sister3.title as category_title3");
$query->join("LEFT", "#__categories as sister3 ON sister3.id = a.catid3");

$categoryEquals = "a.catid ".$type.(int) $categoryId;

Replace with

$categoryEquals = "a.catid ".$type.(int) $categoryId." OR a.catid2 ".$type.(int) $categoryId." OR a.catid3 ".$type.(int) $categoryId;

The following change was added on 03/20/2015

$query->where("a.catid ".$type." (".$categoryId.")");

replace with

$query->where("a.catid ".$type." (".$categoryId.") OR a.catid2 ".$type." (".$categoryId.") OR a.catid3 ".$type ." (".$categoryId.")"); Editing the file components\com_content\views\category\tmpl\blog_item.php
find $url = "item->catid)) . "">" . $title . ""; ?>
get("link_category")) : ?>


Replaced by

$title2 = $this->escape($this->item->category_title2);
$title3 = $this->escape($this->item->category_title3);
$url = "item->catid)) . "">" . $title . "";
$url2 = "item->catid2)) . "">" . $title2 . "";
$url3 = "item->catid3)) . "">" . $title3 . "";
?>
get("link_category")) : ?>
if ($this->item->category_title2) echo JText::sprintf("COM_CONTENT_CATEGORY", $url2);
if ($this->item->category_title3) echo JText::sprintf("COM_CONTENT_CATEGORY", $url3);
?>

if ($this->item->category_title2) echo JText::sprintf("COM_CONTENT_CATEGORY", $title2);
if ($this->item->category_title3) echo JText::sprintf("COM_CONTENT_CATEGORY", $title3);

Note: the same operation with blog_item.php files must be done with the templates you use, if they have this file. For example, it contains the template beez5\html\com_content\category\blog_item.php

Step 6- add the ability to specify several categories in the fronted editor (if necessary)
Editing the file components\com_content\models\forms\article.xml
Are looking for

id="catid"
name="catid"
type="categoryedit"
extension="com_content"
label="JCATEGORY"
description="JFIELD_CATEGORY_DESC"
class="inputbox"
required="true">

Add after

id="catid2"
name="catid2"
type="categoryedit"
extension="com_content"
label="JCATEGORY"
description="JFIELD_CATEGORY_DESC"
class="inputbox"
default="0"
required="false">


id="catid3"
name="catid3"
type="categoryedit"
extension="com_content"
label="JCATEGORY"
description="JFIELD_CATEGORY_DESC"
class="inputbox"
default="0"
required="false">

Editing the file components\com_content\views\form\tmpl\edit.php
find

form->getInput("catid"); ?>

replaced by

form->getInput("catid"); ?>form->getInput("catid2"); ?>form->getInput("catid3"); ?> That's it, now you can work.

As I promised, starting with this article, we will get acquainted with various types of menus in Joomla. And we will start from the very first - this is " List of materials in the archive".

If you don’t know, then read the corresponding article about it first. Also, if you don’t know, then you also need to read about it first.

Now let's start analyzing the menu type - " List of materials in the archive":

We have already discussed the various settings on the left in the article: . But the options on the right differ depending on the type of menu. And now we will get acquainted with the parameters for " list of materials in the archive":

As we can see, there are three blocks. Let's start with the block: " Options - Basic":

  • Order. Here, from the drop-down list, you need to select an option for sorting materials when displaying them on the page.

The second block is much larger. But, nevertheless, I give a description of all the settings:

  • Show links to restricted content. There are links that are open only to registered users (I think you've seen this often). And with this option you can show all visitors that links exist and display them. However, if the visitor is not authorized, he will still not be able to follow the link - he will be asked to log in first.
  • Show title text. Show article titles or not.
  • Title as a link. Display the title in plain text or as a link to the article.
  • Show introductory text. This setting allows you to display the introductory text of materials on the page.
  • Section title. Show or hide the title of the section to which the article belongs.
  • Section title as a link. Display the section title with a link or plain text.
  • name of category. Whether or not to show the name of the category to which the article belongs.
  • Category name as link. Show the category name as a link or in plain text.
  • Author's name. Whether or not to show the author of the article.
  • Creation date and time. Display the date and time the article was created or, conversely, not display it.
  • Last modified date and time. Whether or not to display the date and time the article was last modified.
  • Show navigation. Show article content or not. This refers to materials that consist of several pages.
  • Link more details. If you put " Show" and the material has a main text, then this link will appear. If at least one of the conditions is not met, then the link " More details" will not be displayed.
  • Votes/Article Rating. Show the rating of the article, and also allow users to rate it.
  • Icons. Show print icons, PDF And Email or not.
  • PDF icon. Show or hide icon PDF.
  • Print icon. Show or hide the icon for displaying the printable version of the article.
  • Email icon. Display an icon for the ability to send an article via Email to a friend, or, conversely, not to withdraw.
  • Hits. Show or hide the number of views of an article.
  • Show in RSS. Here you can choose to show only the introductory text or only the main text. It’s a matter of taste, but I advise you to show only the introductory one, so that the person subscribed to your RSS feed, I came to your site to finish reading the article.

The third and final block is " Options - System":

  • Page title. A very important option in which you need to put the tag value<title> on the page where the menu item will lead.
  • Show page title. Whether or not to show the page title not only in the tag<title>, but directly and in the site content.
  • Page class suffix. If you want to make an individual design, then to prevent confusion with others CSS classes, You need to specify a unique suffix that you will use when designing the page.
  • Menu picture. Here you can select a picture that will be located next to the name of the menu item.
  • SSL enabled. This option determines whether a secure connection should be required when following this link. In most cases, you should leave " Ignore".

So we looked at all the settings when creating a menu item like: " List of materials in the archive". In the next article I will continue to describe this process, but with other Joomla menu types.

Multiple circular linking of category materials is the organization of interrelations of category materials in such a way that the loss of articles from the search engine index will occur while minimizing the loss of page weight, and that the organization of interrelations will be controlled, and also that the inclusion of new articles in the category will occur automatically , without the participation of its author.

Note: For the purposes of this article, category is the limitation. And this is due to the fact that for circular linking of materials on the entire site, a more complex mechanism is needed that takes into account the interconnections of the categories themselves. Perhaps, as part of the following articles, a module will be written for the general case. But, at the moment, all subsequent discussion will apply specifically to category materials in CMS Joomla 2.5.

Note: Also, within the framework of this article, a regular website will be considered, without taking into account the influence of linking materials with contextual links and other mechanisms. This will provide a simpler understanding of the essence of multiple rings.

Note: This idea was found on the MaulTalk forum. But the lack of any implementations on the Internet (at least nothing similar was found in search engines) led to both the implementation of the module and the writing of this article.

And now, in a little more simple and understandable language.

A little about the circular linking itself

Linking can be organized using different methods: a large number of links to the promoted page, bottom-up/top-down links, randomly placed links, a ring, a cube and many other methods. Each of these methods has its own goals, and it cannot be said that any of them is better or worse. It all depends on the task.

In this case, the main interest is focused on ring linking, since it provides quite a lot of advantages:

  1. Uniform weight redistribution. Those. all internal weight and weight that comes from other sites is systematically distributed among all materials. When recalculating the weight, each added material will gain its own weight much faster
  2. All added materials at least have links from several other pages on the site. Those. even if the search engine did not get to these materials, or simply did not want to include them in the index, there remains a possibility that the title may attract the visitor, and the material will not be left unnoticed
  3. Easy to understand, even with a large amount of materials you will know the answers to the questions “what? where? why?”
  4. Orderliness. It’s no secret that any blocks with links are seen not only by search engines, but also by visitors (and sometimes even click on these links). This means that you can potentially guide them through all the materials on the site, no matter what page the visitor starts from.
  5. Connectivity of relevant materials. There are no strict requirements for the order in which links are organized. Place the most expected materials nearby, not those required by the scheme

Of course, this method has its problems. But there are also solutions.

The essence of the problem: falling out of the index, controllability, inclusion in the rings

Quite often in articles “How to properly optimize your website” / “Use cross-linking” / etc., the word “ring” is used. The essence of the method is quite simple. Pages are linked in such a way that they form a ring (see picture below).

On the other hand, such a mechanism has several problems. Two are quite small and one is large. The minor ones are overall handling and the inclusion of new materials in the rings. Large - loss of one of the materials from the index. In the case of controllability, we are talking more about the technical side, i.e. on what principle the ring is organized, and what conditions are necessary for the material to be added. In the case of inclusion of new materials, we are talking about the actions of the author, i.e. what needs to be done for the material to be added to the ring.

If the problems of controllability and inclusion of materials can be solved on our own, then in case of falling out of the index, not everything is so simple. As soon as one of the pages falls out, the ring breaks (See picture).

As you can see, after the "M2" page falls out, the adjacent materials no longer transfer weight along the ring. If one page on a site with a small amount of materials falls out, this will not be so critical. Since you can quickly find the dropped page and take all the necessary actions to return it back to the index. As a last resort, you can always adjust the ring.

But try to imagine that not just one page fell out, but several. Yes, there are also quite a lot of materials on the site. Finding all the missing pages will no longer be so easy. Yes, and it’s not a fact that you will be able to quickly detect page dropouts.

What to do?

And this is where the thought arises. What if you make not one, but several rings from materials? Yes, and do it in such a way as not to force the author of the article to run through the entire list of materials in search of “Where should I insert these links?”, but to assign these responsibilities to the site itself.

And the simplest and most understandable option that comes to mind is to make sure that each material links to several previous and next pages (See the picture above). Then, in the event of any material falling out, the following picture will appear:

Despite the fact that the Mat. 35 material fell out, the remaining rings were still preserved (blue arrows point to at least one surviving ring).

Such linking will not only minimize the risk of weight loss when pages fall out, but will also remain manageable. You can always say “where and how” the material will be referenced. At the same time, the addition and removal of materials from the site will remain predictable and occur without the participation of the author.

Practice - Multiple circular linking of category materials

In practice, it turned out that not everything is so simple. Let's look at the most famous modules and plugins (no names, just mechanisms).

Note: We remind you that the main focus when considering modules and plugins is the organization of the ring of materials. Therefore, other advantages and disadvantages of the modules will not be considered.

There are "Related Articles" style modules that primarily rely on meta tags. And most often these are keywords. This mechanism is very similar to a regular tag cloud. And even if you don’t think about it, and are ready to fill in the keywords, then you should look at the settings, and everything will become clear to you. Basically, we are talking about either beautiful display of thumbnails, or multiple filtering and sorting. Organizing a ring in this way is unrealistic.

There are Next/Previous plugins. Their main task is to “guide the user through and through.” Such plugins organize only a chain from beginning to end. The first and last materials will not link to each other. Therefore, it is not possible to build a ring.

Note: It’s a fact, but, unfortunately, in the standard Joomla 2.5 package you cannot display article titles in the “Content - Page Navigation” plugin.

All modules that in any way contain the word “Random” are immediately eliminated, since the likelihood of creating rings or any understandable structure with such tools tends to zero. Plus, such modules lead to the appearance of blinking links, which can negatively affect search engine rankings.

If we look at modules for contextual linking, then their main task is to raise certain pages for certain queries. Of course, you can organize a ring using such modules, but it will cost you a lot of nerves and sleepless nights.

Thus, it turns out that creating even one ring using existing means is either not easy or even impossible. All this led to one simple thought - we need our own expansion.

Note: Perhaps there are special tools for these purposes, but, unfortunately, they have never been found.

Note: Of course, you can still create rings manually, but imagine how much effort it will require from you not only to add, but also to ensure that the ring does not break anywhere.

We write our own module for multiple linking with rings

Perhaps the title of this subsection scared you a lot. If this is the case, then scroll to the end of the article, there is a link to download a ready-made and working module.

The first thing you need to start with is coming up with a name. Without further ado, let’s call the module “Ring linking of category materials.” The technical name will be "mod_circle_link_mat_by_cat".

The next thing to do is to create a standard file structure.

  • css
    • mod_circle_link_mat_by_cat.css
    • index.html
  • language
    • ru-Ru
      • mod_circle_link_mat_by_cat.ini
      • mod_circle_link_mat_by_cat.sys.ini
      • index.html
    • index.html
  • tmpl
    • default.php
    • index.html
  • helper.php
  • index.html

Now, let’s look at the purpose of each of the files in order.

  • index.html is an empty file that is located in all directories, including the main module directory
  • mod_circle_link_mat_by_cat.php - module entry point. This file will be launched first when the module is launched, and it will also launch other files (except for languages ​​and the configuration file)
  • mod_circle_link_mat_by_cat.xml is a configuration file that includes all the meta settings of the module. In this case we use:
    • module name and description
    • files to copy
    • various parameters that will be displayed in the administrative panel
    • localization connection
  • mod_circle_link_mat_by_cat.css - file with styles. It is empty, and was created for only one purpose, so that later, when adjusting the styles to your site (if required), you do not need to mix the general site styles with the module styles
  • mod_circle_link_mat_by_cat.ini - localization file
  • mod_circle_link_mat_by_cat.sys.ini - localization file
  • default.php - display template. Used to generate HTML code that will be displayed inside the block with the module
  • helper.php - all the necessary functions for receiving data will be placed in this file

Configuration file - mod_circle_link_mat_by_cat.xml

The configuration file has a fairly simple and understandable structure. First comes a description of the module itself, including fields such as author and description. The "files" tag then lists the file and folder structure that needs to be copied during installation. This is followed by the “languages” tag with information about the location of the localization files in the module. And finally, there is the “config” section, in which the necessary parameters are defined.

If all sections except "config" are purely technical and can simply be copied, then a little explanation needs to be added for the parameters section.

  • isMain is a checkbox that prevents data from being displayed on the main page. Enabled by default
  • exceptCat - a line that lists, separated by commas, all category IDs for which the module should not display links. For example, the category "Uncategorized". By default, the field is empty
  • prev_mat_number - the number of previous materials (including the ring) that need to be displayed. Default value 3
  • next_mat_number - the number of next materials (including the ring) that need to be output. Default value 3

Note: Various names in the form "MOD_CIRCLE_MAT_BY_CAT_ISMAIN" are constants that will be taken from the localization files.

Circular linking of category materials FBT 1.0.0 June 27, 2014 mod_circle_link_mat_by_cat.xml mod_circle_link_mat_by_cat.php index.html helper.php tmpl css language ru-RU/ru-RU.mod_circle_link_mat_by_cat.ini ru-RU/ru-RU.mod_circle_link_mat_by_cat.sys.ini

Module entry point - mod_circle_link_mat_by_cat.php

This file starts to be executed first. And, in fact, its main task is to connect all the necessary Joomla resources, receive data and transfer it to the display template.

In this case, the only resources needed are routing for the correct compilation of links. Everything else is already connected.

Obtaining data is a fairly large task. That is why it was moved to a separate helper.php file. In the current file there is only a call to the "get list" function. Well, and at the very end, calling a template for composing html code. There are no special difficulties here.

addStylesheet(JURI::root(true) . "/modules/".$module_name."/css/".$module_name.".css"); // Parameters $prevCount = $params->get("prev_mat_number"); $nextCount = $params->get("next_mat_number"); $idMat = JRequest::getVar("id",""); $idCat = $helper->getSection($idMat); // Check for the main page $menu = &JSite::getMenu(); // Excluded categories $exceptCat = explode (",", $params->get("exceptCat")); $isInExceptCat = false; // Check the category for exclusion $countExceptCat = count ($exceptCat); for($i = 0; $i< $countExceptCat; $i++) { if ((int) $exceptCat[$i] == $idCat) { $isInExceptCat = true; break; } } // Проверяем параметры if(!$isInExceptCat && ($params->get("isMain") != "1" or $menu->getActive()!= $menu->getDefault())) ( // Get the list $showList = $helper->getList($idMat, $idCat, $prevCount, $nextCount); // Output via template require (JModuleHelper::getLayoutPath($module_name, $params->get("layout", "default"))); ) ?>

Localization files - mod_circle_link_mat_by_cat.ini

Localization files are built in a simple way. Enumerating "key" = "value" pairs. There are no difficult places here.

Note: We strongly recommend that when composing names, you use unique key names so as not to accidentally overlap with other localizations. For example, when composing you can use the construction "(MODULE_NAME) + _ + (KEY)".

File mod_circle_link_mat_by_cat.ini

MOD_CIRCLE_MAT_BY_CAT="CircleLinkByCat" MOD_CIRCLE_MAT_BY_CAT_PREV_MAT_LBL="Number of previous materials" MOD_CIRCLE_MAT_BY_CAT_PREV_MAT_LBL_DESC="Indicate the desired number of previous materials" MOD_CIRCLE_MAT_BY_CAT_NEXT_MAT_LBL="Number of next materials" MOD_CIRCLE_MAT_BY_CAT_NEXT_MAT_LBL_DESC="Indicate the desired quantity of the following materials" MOD_CIRCLE_MAT_BY_CAT_ISMAIN="Exclude main" MOD_CIRCLE_MAT_BY_CAT_ISMAIN_DESC ="If you do not want the module to be connected on the main page, then set the item to YES" MOD_CIRCLE_MAT_BY_CAT_EXCEPTCAT="Exclude categories" MOD_CIRCLE_MAT_BY_CAT_EXCEPTCAT_DESC="If your site has categories that need to be excluded, then enter their ID separated by commas"

File mod_circle_link_mat_by_cat.sys.ini

MOD_CIRCLE_MAT_BY_CAT="Circular linking of category materials"

Display template - default.php

The whole purpose of the template comes down to simply displaying a list of materials in the ul tag. If you use a specific layout, for example, using divs, then you can always correct this code.

0) { ?>

Making a helper - helper.php

This file is quite large, it contains about 250 lines. Therefore, the main focus will be on two SQL queries and one piece of code that generates actual links to materials. You can view the full source file in the module archive.

The main problem when building queries is ring closure. Since it is necessary, upon reaching the first and last materials, to receive the last and first articles, respectively.

Code to get previous articles:

/* get previous articles */ select id, link, title, access, alias, 0 as afterCircle from (select * from (select id, "" as link, title, access, alias from #__content where /* all previous articles in categories in published state */ catid = ".$idCat." and id< ".$idMat." and state >0 /* publication date has not expired */ and (publish_down is null or publish_down >< NOW()) /* нужно получать с конца списка */ order by id desc limit 0,".$prevCount.") sort order by id asc) a union /* получаем данные для случая, если предыдущих статей меньше, чем надо */ select id, link, title, access, alias, 1 as afterCircle from (select * from (select id, "" as link, title, access, alias from #__content where /* все последующие статьи в категории в опубликованном состоянии */ catid = ".$idCat." and id >".$idMat." and state > 0 /* publication date has not ended */ and (publish_down is null or publish_down >= NOW()) /* material published */ and (publish_up is null or publish_up< NOW()) /* нужно получать с конца списка */ order by id desc limit 0,".$prevCount.") sort order by id desc) b

The request may seem a little complicated and large, but in fact everything is very simple. The first part, before union, selects from all materials only the previous ones for this article. The second part, after union, is needed to obtain the latest materials. Those. as if the search for materials around the ring continues.

Example. Let's say there are 5 materials in a category:

  • A B C D E.

For simplicity, they follow each other in alphabetical order. And you want to display the two previous materials for article "B". In this case, the previous articles are both "A" and "D" (since "D" is the last material). Material "A" will be found by the first part of the query, and "D" will be found by the second part of the query.

To obtain the following materials, the SQL query differs only in the checks and sorting order. The code itself:

/* get the following articles */ select id, link, title, access, alias from (select * from (select id, "" as link, title, access, alias from #__content where /* all the following articles in the category in published state */ catid = ".$idCat." and id > ".$idMat." and state > 0 /* publication date has not expired */ and (publish_down is null or publish_down >= NOW()) /* material published */ and (publish_up is null or publish_up< NOW()) /* нужно получать с начала списка */ order by id asc limit 0,".$nextCount.") sort order by id asc) a union /* получаем данные для случая, если следующих статей меньше, чем надо */ select id, link, title, access, alias from (select * from (select id, "" as link, title, access, alias from #__content where /* все предыдущие статьи в категории в опубликованном состоянии */ catid = ".$idCat." and id < ".$idMat." and state >0 /* publication date has not expired */ and (publish_down is null or publish_down >= NOW()) /* material published */ and (publish_up is null or publish_up< NOW()) /* нужно получать с начала списка */ order by id asc limit 0,".$nextCount.") sort order by id asc) b

As you can see, the main difference is only in the reverse order of searching and sorting data.

If we consider an example, then for article “D” the two subsequent materials are: “D” and “A” (since “A” is the first in the list).

After all the lists have been received and combined into one common list, it is necessary to generate links for them. The following code is responsible for this part:

// For all received elements, add a link if(count($showList) > 0) ( $countShowList = count ($showList); for ($i = 0; $i< $countShowList; $i++) { /* Получаем пункт меню */ $itemid = &JSite::getMenu()->getItems("link", "index.php?option=com_content&view=article&id=".($showList[$i]->id), true); /* If the menu item exists, then create a link for it */ if(!empty($itemid)) ( $showList[$i]->link = JRoute::_("index.php?Itemid=".$itemid ->id); ) /* If the menu item does not exist, then we create a link taking into account SEF */ else ( /* Get the menu item for the category */ $catitemid = JSite::getMenu()->getItems("link", "index.php?option=com_content&view=category&id=".$idCat, true); /* If the menu item exists, then create a link for it */ if(!empty($catitemid)) $showList[$i]-> link = JRoute::_("index.php?option=com_content&view=article&id=".($showList[$i]->id).":".($showList[$i]->alias)."&catid =".$idCat."&Itemid=".$catitemid->id); /* If the menu item does not exist, then we create a link taking into account SEF */ else $showList[$i]->link = JRoute::_( "index.php?option=com_content&view=article&id=".($showList[$i]->id).":".($showList[$i]->alias)."&catid=".$idCat); ) ) )

The whole catch is that when accessing a material through a menu item, a completely different link is generated for it (this is a frequently used method to get rid of the material ID in the Url). In this case, it is important that in the “JRoute::_("index.php?Itemid=".$itemid->id)” construction the “Itemid” parameter is written in a case-sensitive manner. If you write not “Itemid”, but “itemid”, then the output you will get is a scary-looking link. What is this connected with? It's difficult to say, but the fact remains that the parameter is case sensitive.

Now all we have to do is zip the files into a Zip archive. To do this, you can use free archivers. And that's it, the module is ready!

Install and configure the resulting module

After all the work done, all that remains is to install and configure the module.

Installation is quite simple. All you need is to open the "Extension Manager" and download the archive with the module.

Immediately after installation, this module will be added to the general list of modules. By default, it will be disabled.

Note: You can also create several more modules for linking, since its type will be available in the general list for adding modules.

Now you need to configure the module. Left-click on the module. And let's move on to setup.

First of all, you need to configure the basic parameters, namely: indicate the position of the module, change the status to “published” and decide on the question “Will you display the name of the module?”

Now you need to move on to setting up the standard block "Binding to menu items". The setup itself is no different from setting up any other module. In this case, the “On all pages” option was selected.

We're done with the standard parameters. We configure the parameters of the module itself. We indicate whether the module will be displayed on the main page. We list the excluded categories. For example, we indicate the category ID "Uncategorized" (for each site this category may have a different ID, so first go to the "category manager" and find the one you need). Select the number of previous and next materials.

Rating 4.83 (9 Votes)


In the next, 42nd lesson on creating a Joomla website, we’ll see what the module is for, how to create and how to configure the “List of Category Materials” module.

What is it needed for

The module in question belongs to the “Materials” group of modules. There are a total of 6 modules in this group.

The “List of Category Materials” module is needed to display on the site in any position for modules, a list of articles (materials) from a selected category or several selected categories.

Module directory

The folder with this module is called . Its catalog contains:

  • tmpl directory;

Files helper.php; mod_articles_category.php; mod_articles_category.xml.

You will find the catalog itself in the catalogue.

How to create

To create a module List of category materials, follow these simple steps:

  • Log in to the administrative part of the site with the rights necessary to create modules. For example, super administrator;
  • From the top menu, go to the “Modules” tab;
  • On the page with a list of already created modules, click the “Create” button. It is green;
  • In the list of modules, select the module called “Materials - List of category materials”;
  • Fill in the module settings, select the module’s position on the site and save it;
  • After clearing the cache (if you use it), the module will be visible on the site in the specified position.

Settings

Let's look at the settings of our module. They are not complicated. On the module creation tab 8 tabs:

Module; Linking to menu items; Filtering, sorting, grouping, display options; Extra options; Access rights.

Module

An interesting setting that has two display mode parameters:

  • Normal: The module is simply created and shown where specified;
  • Dynamic: In this mode, the system itself decides where to display this module.

Linking to menu items

In this setting, we indicate on which pages of the site to display this module. The choice is made based on the items created in the site menu.

For example, to show a module ONLY on the main page, you need to select Module Binding - “Only on specified pages” and select the main page from the menu list.

Filtering options

class="eliadunit">

This is where you must select one or more categories whose materials you want to display as a list in the module.

It is also possible to remove “Featured Materials” from the list, include or remove child categories, and specify the number of articles in the list.

Sorting

Sorting parameters rank the list of materials by title and 9 other options. You can specify forward or reverse sorting.

Grouping

If you wish, you can group materials by year, month, authors or categories (if there are several of them).

Display options

Important settings item, as it specifies the appearance of the list of materials. By default, only the article title is shown.

If you wish, you can supplement the list with the publication date of the material, category, number of views, author, introductory text, and the “More details” link.

Extra options

Here you can change the appearance of the module by specifying your own pre-loaded module styles (Module CSS Class Suffix item) or use one of the system module styles (Module Style item).

The Bootstrap Size option will split the list into columns. Value "0" no columns.

Rights

If your site is multi-user, then you need to set user rights according to your site management rights scheme.

After the settings, do not forget to check the position of the module on the “Module” tab, show or hide its name, which is required, and write a note for yourself.

Conclusion

In this article, you looked at the last module from the “Materials” group called List of materials in the Joomla site category.



Have questions?

Report a typo

Text that will be sent to our editors: