1

When displaying articles in blog layout on my website, I want the respective article link on the title and the whole intro text.

I looked at the code in components/com_content/views/category/tmpl/blog_item.php, but I was not able to find a solution.

Does anyone know how to do that?

3
  • You want the whole article "in place of" the intro text? Sep 10, 2018 at 8:41
  • 1
    no, as you see in blog layout, the link to the full article is only if you click on title. i want link on the intro text as well to the full article(e.g. if we click on intro text the whole article will open) Sep 10, 2018 at 9:13
  • See comment by KlintWeb below my asnwer. You certainly want to do any such changes inside a template override, to avoid losing your modifications after a Joomla Update. Sorry, I totally missed to note this in my answer.
    – FFrewin
    Sep 12, 2018 at 14:35

1 Answer 1

2

Important Note after KlintWeb comment:

You certainly want to do any such changes inside a template override. Search in this site and also in the web about Joomla Template Overrides to find out how you can create them.


How to wrap the intro-text inside a link to the article:

In components/com_content/views/category/tmpl/blog_item.php there is a piece of code:

<?php echo $this->item->introtext; ?>

This one echoes the introtext of the article.

A a few lines below, there is:

<?php if ($params->get('show_readmore') && $this->item->readmore) :
    if ($params->get('access-view')) :
        $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language));
    else :
        $menu = JFactory::getApplication()->getMenu();
        $active = $menu->getActive();
        $itemId = $active->id;
        $link = new JUri(JRoute::_('index.php?option=com_users&view=login&Itemid=' . $itemId, false));
        $link->setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language)));
    endif; ?>

This one generates the link for the read-more button (if the button is enabled). It also takes into consideration if the content is restricted.


So, now you have all the needed elements to do what you want to do.

Just wrap your intro-text with an <a> element and use the article link for the href attribute.


*If you don't have restricted content, then just use:

$link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid, $this->item->language));

2
  • This will not work forever. It might get overridden by an update in the future. My advice is never to make changes in the core files. Especially not, when you can make overrides in templates/your-template/html/...
    – KlintWeb
    Sep 12, 2018 at 13:26
  • @KlintWeb - you are absolutely right. I completely missed to mention this.
    – FFrewin
    Sep 12, 2018 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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