A
A
Alexon Classic2018-12-02 03:38:57
Joomla
Alexon Classic, 2018-12-02 03:38:57

How to add category name and date to intro_image.php file in Joomla 3?

Hello everyone !
I have a file:

templates/my_template/html/layouts/joomla/content/intro_image.php

I need to insert a code into it that would display the name of the category that includes the material whose intro image is displayed on the site + add the publication date of this material ... That is, I need to transfer the category name and publication date of the material from blog_item EXACTLY to the file
templates/my_template/html/layouts/joomla/content/intro_image.php

I don’t understand how to do this ...
I tried it in different ways:
$this->category->text
$this->category->title

and a bunch of other code like:
$title = $this->escape($displayData['item']->category_title);

Nothing happens... I do n't want to write
queries to the database so as not to load the server once again. I would like to somehow play around with Joomla files, because the whole point is that the category itself (its name and link) is formed in the file
templates/my_template/html/layouts/joomla/content/info_block/category.php

and the date of publication in
templates/my_template/html/layouts/joomla/content/info_block/publish_date.php

But, in order to get to them from the same blog_item , there is a long line with a check:
if ($useDefList && ($info == 0 || $info == 2)) :
echo JLayoutHelper::render('joomla.content.info_block.block', array('item' => $this->item, 'params' => $params, 'position' => 'above'));
endif;

which "forces" to go through several more (above) files... Just copy the code from these files and paste it into intro_image.php - it doesn't work...
Paste the code from blog_item.php:
echo JLayoutHelper::render('joomla.content.info_block.block', array('item' => $this->item, 'params' => $params, 'position' => 'above'));

in intro_image.php - not possible, because the exceptions pop up...
Can someone tell me how to do this?
Thanks in advance for your replies !

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexon Classic, 2018-12-04
@AlexonClassic

It turned out that you can still do without a query to the database ...
It was enough to
create 2 files:

  1. category_title.php, in which to write this:
    <?php defined('JPATH_BASE') or die;
      echo $this->escape($displayData['item']->category_title);
    ?>
  2. publish_date_no_html.php, in which to write this:
    <?php defined('JPATH_BASE') or die;
      echo JHtml::_('date', $displayData['item']->publish_up, JText::_('DATE_FORMAT_LC2'));
    ?>
and in blog_item.php add:
$cat_name = JLayoutHelper::render('joomla.content.info_block.category_title', array('item' => $this->item));
  $art_publish_date = JLayoutHelper::render('joomla.content.info_block.publish_date_no_html', array('item' => $this->item));
  JRequest::setVar('cat_name', $cat_name, 'post'); //задаем глобальную переменную
  JRequest::setVar('art_publish_date', $art_publish_date, 'post'); //задаем глобальную переменную

and already in intro_image.php, add this:
$cat_name = JRequest::getVar('cat_name', '', 'post'); //считываем глобальную переменную
  $art_publish_date = JRequest::getVar('art_publish_date', '', 'post'); //считываем глобальную переменную

and already in the right place, using echo to display the name of the category and the date of publication of the material...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question