Hallo Leute, ich bin kein Profi, ob ich seit über 10 Jahre mit Joomla arbeite,
ich will in Joomla 4 das selbe wie in Joomla 3 und 2 ereicht habe,
in Overrides Pfad ist: html/layouts/joomla/content/intro_image.php
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright (C) 2013 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\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Utilities\ArrayHelper;
$params = $displayData->params;
$images = json_decode($displayData->images);
if (empty($images->image_intro))
{
return;
}
$imgclass = empty($images->float_intro) ? $params->get('float_intro') : $images->float_intro;
$extraAttr = '';
$img = HTMLHelper::cleanImageURL($images->image_intro);
$alt = empty($images->image_intro_alt) && empty($images->image_intro_alt_empty) ? '' : 'alt="' . htmlspecialchars($images->image_intro_alt, ENT_COMPAT, 'UTF-8') . '"';
// Set lazyloading only for images which have width and height attributes
if ((isset($img->attributes['width']) && (int) $img->attributes['width'] > 0)
&& (isset($img->attributes['height']) && (int) $img->attributes['height'] > 0))
{
$extraAttr = ArrayHelper::toString($img->attributes) . ' loading="lazy"';
}
?>
<figure class="<?php echo htmlspecialchars($imgclass, ENT_COMPAT, 'UTF-8'); ?> item-image">
<?php if ($params->get('link_intro_image') && ($params->get('access-view') || $params->get('show_noauth', '0') == '1')) : ?>
<a href="<?php echo Route::_(RouteHelper::getArticleRoute($displayData->slug, $displayData->catid, $displayData->language)); ?>"
itemprop="url" title="<?php echo $this->escape($displayData->title); ?>">
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?>
itemprop="thumbnailUrl"
<?php echo $extraAttr; ?>
/>
</a>
<?php else : ?>
<img src="<?php echo htmlspecialchars($img->url, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $alt; ?>
itemprop="thumbnail"
<?php echo $extraAttr; ?>
/>
<?php endif; ?>
<?php if (isset($images->image_intro_caption) && $images->image_intro_caption !== '') : ?>
<figcaption class="caption"><?php echo htmlspecialchars($images->image_intro_caption, ENT_COMPAT, 'UTF-8'); ?></figcaption>
<?php endif; ?>
</figure>
Alles anzeigen
das Ziel ist folgenes zu erreichen:
- wenn ein bild für Intro vorhanden ist, zeige es,
- wenn nicht, dann wenn für Full (Beitrag) vorahnden ist, zeige es,
- wenn nicht, dann wenn für Kategorie vorhanden ist, zeige es,
- wenn nicht, dann zeige von URL (Pfad),
in Joomla 3 und 2 war so realiesierbar:
<?php
$images = json_decode($displayData->images);
$category = JCategories::getInstance('Content')->get($displayData->catid);
if (isset($images->image_intro) && !empty($images->image_intro)) { $image = htmlspecialchars(JURI::root().$images->image_intro); }
elseif (isset($images->image_fulltext) && !empty($images->image_fulltext)) { $image = htmlspecialchars(JURI::root().$images->image_fulltext); }
elseif ($category->getParams()->get('image')) { $image = htmlspecialchars(JURI::root().$category->getParams()->get('image')); }
else { $image = htmlspecialchars(JURI::root().'images/no-image.png'); }
?>
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, $displayData->catid)); ?>">
<img src="<?php echo $image; ?>" itemprop="thumbnailUrl" />
</a>
Alles anzeigen
in Joomla 4 funtioniert nicht wie es soll die o.g. code, aber wenn man auskomentiert dies code hier, dann funtioniert genaor so wie ich mich wünsche,:
die kmplete Code sieht so aus:
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright (C) 2013 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\HTML\HTMLHelper;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Utilities\ArrayHelper;
$params = $displayData->params;
$images = json_decode($displayData->images);
/*
if (empty($images->image_intro))
{
return;
}
*/
$imgclass = empty($images->float_intro) ? $params->get('float_intro') : $images->float_intro;
$extraAttr = '';
$img = HTMLHelper::cleanImageURL($images->image_intro);
$alt = empty($images->image_intro_alt) && empty($images->image_intro_alt_empty) ? '' : 'alt="' . htmlspecialchars($images->image_intro_alt, ENT_COMPAT, 'UTF-8') . '"';
// Set lazyloading only for images which have width and height attributes
if ((isset($img->attributes['width']) && (int) $img->attributes['width'] > 0)
&& (isset($img->attributes['height']) && (int) $img->attributes['height'] > 0))
{
$extraAttr = ArrayHelper::toString($img->attributes) . ' loading="lazy"';
}
?>
<?php
$images = json_decode($displayData->images);
$category = JCategories::getInstance('Content')->get($displayData->catid);
if (isset($images->image_intro) && !empty($images->image_intro)) { $image = htmlspecialchars(JURI::root().$images->image_intro); }
elseif (isset($images->image_fulltext) && !empty($images->image_fulltext)) { $image = htmlspecialchars(JURI::root().$images->image_fulltext); }
elseif ($category->getParams()->get('image')) { $image = htmlspecialchars(JURI::root().$category->getParams()->get('image')); }
else { $image = htmlspecialchars(JURI::root().'images/no-image.png'); }
?>
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($displayData->slug, $displayData->catid)); ?>">
<img src="<?php echo $image; ?>" itemprop="thumbnailUrl" />
</a>
Alles anzeigen
Meine Frage ist: wie mache ich es in Joomla 4, oder soll ich lassen wie in Joomla 3 und 2,
vielen Dank im Voraus, Guri.