6 minutes reading time (1219 words)

Keyword or not keyword tag, that is the question

Keyword or not keyword tag, that is the question

2023-DEC-Keyword-or-no-keyword

Recently, a friend of mine posted a singular question on a famous social media:

Do you still use the keyword field in articles?

Since decades, the content of the keyword meta tag isn't used anymore by search engines as a ranking factor.
Of course, you can still use it even if there's no impact for your content visibility but there's probably others smart use cases.

Joomla is extremely powerful when it comes to content management. That's why we all should try to stick to the core as much as possible.
I'm always amazed to find different or new possibilities to solve a problem only using the native features of our beloved CMS.

In this article, I'll show you an interesting use case of the keyword field.

What are the benefits to stick to the core?

Your content is powered by com_content
You can manage it easlily, you have a full control on it, and more important, you have many options to display it.

No need to install and maintain an extension
You don't have an extension to install and maintain. No learning curve to endure. Forget the heavy CCK and others page builders, because in most of the cases, you only need Joomla to get the desired result.

Improve your Joomla skills with the core
As said previously, I'm always amazed to find clean solutions thanks to Joomla native features. Thanks to this use case of the keyword field, I guess you will learn something new and useful about Joomla.

What is the starting point?

When it's come to add a new feature to display content on frontend, many people have the reflex to... add an extension.

Of course, there's no other choice in some cases but this shoudn't be a systematic answer of every problem we're facing.

As you may know, Joomla comes with so many core features that your solution is probably already in your site.

In such situation, my very first reflex is always to look at a core solution because Joomla offers A LOT.
And I strongly recommend you to adapt this healthy attitude.

Let's go back to out keyword field.
The content of this field is mainly used in 2 scenarios in Joomla:

added in the meta keyword tag displayed in the source code of the page used by the module mod_related_items.

If you're not very familiar with this module, here is the complete description:

This module displays other Articles that are related to the one being viewed. These relations are established by the Keywords.
All the keywords of the current Article are searched against all the keywords of all other published Articles. For example, you may have an Article on "Breeding Parrots" and another on "Hand Raising Black Cockatoos". If you include the keyword "parrot" in both Articles, then the Related Items Module will list the "Breeding Parrots" Article when viewing "Hand Raising Black Cockatoos" and vice-versa.

As the search engines don't use the content of this tag any more as an indexing factor, many of us have abandoned this field.

In my opinion, it's too early to bury this interesting core feature.

And what if the keyword field could be useful again?

Let's go back to the description of the module mod_related_items: this module displays a list of articles related to the article currently readed. To be related, the articles should have the same keyword(s).

Now, imagine you have several authors on your website. It could be useful for the readers and nice for your authors to display some of their articles below their articles.

And rather than installing another extension, I'll show you how to acheive this simply using the keyword field.

We'll see all the details below but thanks to this trick, you'll be able to display some articles from the same author of the current article with only one module.

Yes, one core module for all your authors.

Only one core module to rule them'all.

Impossible to be lighter and simplier.

The module override

For this example, we want to display at the bottom of every article, 4 related items with for each item, the intro image, the title, and the intro text.

By default, the module mod_related_items displays only the title and the date of the related item. So we need to override it to get the desired result.

Here is the code (feel free to copy and adapt it to your needs).
I've added some comments for an easier reading.

<?php /** * @package Joomla.Site * @subpackage mod_related_items * @author web-eau.net * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Layout\FileLayout; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Component\Content\Site\Helper\RouteHelper; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; ?> <div class="pb-5 col-sm-12"> <div class="row row-cols-1 row-cols-md-4 g-4 relateditems<?php echo $moduleclass_sfx; ?>"> <?php foreach ($list as $item) : ?> <!-- calling the intro image --> <?php $article_images = json_decode($item->images); $article_image = ''; $article_image_alt = ''; if(isset($article_images->image_intro) && !empty($article_images->image_intro)) { $article_image = $article_images->image_intro; $article_image_alt = $article_images->image_intro_alt; }?> <div class="col"> <div class="h-100 bg-white"> <!-- displaying the intro image with a link on it --> <a href="/<?php echo $item->route; ?>"> <img class="d-block card-img-top img-fluid" src="/<?php echo $article_image; ?>" alt="<?php echo $article_image_alt; ?>" > </a> <div class="card-body p-4"> <!-- article title with a link on it --> <h3 class="card-title"> <a class="mod-articles-category-title <?php echo $item->active; ?>" href="/<?php echo $item->route; ?>"> <?php echo $item->title; ?> </a> </h3> <!-- introtext truncated at 300 characters --> <small><?php echo JHTML::_('string.truncate', $item->introtext, 300, false, false) ; ?></small> </div> </div> </div> <?php endforeach; ?> </div> </div>

Here are the settings of the module mod_related_items:

image

Note - In this example, the module is published in a template position right below the main component.

The article override

To be consistent and relevant, we want to display dynamically the name of the author with these related items. To acheive this, create an article override for the articles of your authors.

Then, copy/paste the following code at the bottom of this override:

<h3 class="pt-5"> Others articles from <?php echo $this->item->metakey ; ?> </h3> <hr class="my-4">

Note - The syntax <?php echo $this->item->metakey ; ?> displays the content of the keyword field.

As usual, it's always possible to improve this trick and these overrides but I'm sure this use case of the keyword field associated to the module mod_related_items will offer interesting perspectives to creative and imaginative people.

The only limitation encountered here is the order of the related items displayed. It seems that the module displays by default the oldest items first.

image

Et voilà!
Thanks to the keyword field, you can display some related items from the same author.
Thanks to the override, you can give to these related items, the exact design you want.
Thanks to the module mod_related_items, you don't need to add an extension.

Thanks to this 100% Joomla solution, you shouldn't face any issue while migrating your site in future.

All these Joomla features are natives and free.
Because the only limit is your imagination, let us know in the comment section below how you use the keyword field.

×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Less than 5 mins to change the design of the searc...
How to volunteer for Joomla without volunteering f...
 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Guest
Saturday, 20 July 2024

Captcha Image