2

Is there a way to add an id-tag to the article HTML through the Joomla interface?

At the moment I add a div in the source of the article so i get:

<article class="item leading-0 clearfix">
    <div id="about-me">
        <p>Article text.</p>
    </div>
</article>

However, i would prefer setting it in the interface so that i get directly:

<article class="item leading-0 clearfix" id="about-me">
    <p>Article text.</p>
</article>

is this possible?

1

You can get the current article id like this:

$article_id = JFactory::getApplication()->input->get('id');

Create an override for JOOMLAROOT\components\com_content\views\article\tmpl\default.php by copying the file to JOOMLAROOT\templates\YOURTEMPLATE\html\com_content\article\default.php. Then add the following code wherever you want to add the article id:

<?php echo intval($article_id); ?>

Example:

<article class="item leading-0 clearfix" id="<?php echo intval($article_id); ?>">
    <p>Article text.</p>
</article>

I added intval() in order to get the article ID only, but you can remove it if you want. If you do, $article_id will be something like 24joomla because JFactory::getApplication()->input->get('id') seems to return both the id and the alias together. I'm not sure why, maybe someone else can explain it?

  • Thanks for pointing me in the right direction! Took a bit of tinkering but figured it out due to your answer – nluigi Sep 3 '15 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.