Joomla intro image as a sitelink

I want to make an intro-image of a joomla article to behave as read more, and a title link. Thus, the user clicks the image, and the product is loaded.

I'm not a PHP expert, but maybe this is readmore links code:

<a href="<?php echo $this->item->readmore_link; ?>" class="button<?php echo $this->item->params->get('pageclass_sfx'); ?>"> <?php if ($this->item->readmore_register) : echo JText::_('Register to read more...'); elseif ($readmore = $this->item->params->get('readmore')) : echo $readmore; else : echo JText::_("Read Article"); endif; ?></a> 

This is what I want to do with every intro image on my joomla site. Thanks!

+6
source share
7 answers

Just decided!

Your way of thinking has helped me. Thanks!

here is my code:

  <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>"> <?php $images = json_decode($item->images); if (isset($images->image_intro) and !empty($images->image_intro)) { $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; $class = (htmlspecialchars($imgfloat) != 'none') ? ' class="size-auto align-'.htmlspecialchars($imgfloat).'"' : ' class="size-auto"'; $title = ($images->image_intro_caption) ? ' title="'.htmlspecialchars($images->image_intro_caption).'"' : ''; echo '<img'.$class.$title.' src="'.htmlspecialchars($images->image_intro).'" alt="'.htmlspecialchars($images->image_intro_alt).'" />'; } echo $this->item->introtext; ?> </a> 
+6
source

for Joomla 2.5:

in your override for _item.php (Location: yourtemplate \ html \ mod_articles_news \ item.php) put the following line:

 <?php if ($params->get('image')) : ?> <?php $images = json_decode($item->images); ?> <?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?> <a href="<?php echo $item->link;?>"><img src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/></a> <?php endif; ?> <?php endif; ?> 

Place it where you want it to appear For example, after:

 <?php echo $item->beforeDisplayContent; ?> 

Your opening image has become a link. The isset part, ensures that if the viewer uses Internet Explorer, it does not display a small red box.

For information only: in blog_item.php you can find sample code, as shown in the article. Here you can also find the code for imagefloat, etc.

 <?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?> <?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?> <div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>"> <img <?php if ($images->image_intro_caption): echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"'; endif; ?> src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/> </div> <?php endif; ?> 
+2
source

So let me start by explaining what the code you posted above does. The entire block of code generates one link: there is a group of if statements that are defined based on some settings. For example, if you have determined that people must register in order to read more, the link will say "Register to learn more ..."

The part that we are interested in here, however, since we want to turn images into links, is the URL to which we want to link the images. This is true on the first line:

 <a href="<?php echo $this->item->readmore_link; ?>" 

therefore, we know that the URL is provided dynamically thanks to $item->item->readmore_link , and all this code echoes in HTML.

It remains only to edit your Joomla template on the page on which you have images (probably the same file from which you took this code). It seems like this should be part of a larger PHP loop that iterates over all posts. Somewhere above where you found this code, there should be code for the inline image that matches this message.

I'm not sure how it will look, it could be <img src="<? stuff here; ?> /> , Or it could be dynamically generated. Keep reading. If you still don't know where to find it at the end, edit your post with the full template code in which you received the above shutdown. No matter what it looks like, in the next step it is called <WHATEVER IMAGE CODE YOU FOUND ABOVE> :

You should wrap this image with a tags so that it looks like this:

 <a href="<?php echo $this->item->readmore_link; ?>"> <WHATEVER IMAGE CODE YOU FOUND ABOVE> </a> 

That should do it. Let me know if you have any problems, I will be more than happy to make my post more specific if you can provide more detailed information, but I tried to explain it well enough so that you can understand it with the help of the couple trying.

+1
source

As you stated that you are not a PHP expert, it seems your best bet would be to use the Joomla extension, which has similar features to what you want.

I believe mod_minifrontpage will work just the way you need it. It allows you to display a list of articles, and it generates thumbnails for these articles based on the first image you want to link to.

+1
source

J has built-in images starting from version 1.7.5 and now in the latest version 2.5.3 you need to change the default values ​​for the component_content,

You can do this in two ways by editing the views in your application / components / com_content / views /

or use template overrides, first you need to know if your IS template uses overrides, if you edit the component views in the component itself, you will not see the changes.

to check this go to site_name / templates / template_name / html and check if there is a folder name com_content,

if so, how your template uses overrides, and any changes must be made through not through the component

now to the actual code

this is in Components \ com_content \ views \ featured \ tmpl \ default_item.php (DEFAULT ARTICLES SPECIFY THIS)

 <?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?> <?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?> <div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>"> <img <?php if ($images->image_intro_caption): echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"'; endif; ?> src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/> </div> <?php endif; ?> 

all you have to do is wrap the element around the IMG tag with a readmore link like this

 <a href="<?php echo $this->item->readmore_link; ?>"> <img <?php if ($images->image_intro_caption): echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"'; endif; ?> src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/> </a> 

DO NOT forget that if there is a template override for com_content, you need to edit featured / default_item.php inside it

+1
source

In Joomla 3.1, the intro_image layout has been moved to the layouts / joomla / content folder. In my situation, it is called from com_content / views / category / tmpl / blog_item.php as follows:

 <?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?> 

I moved this file to my template / html / com _content / category / blog_item.php, and then wrapped the JLayoutHelper call like this:

 <?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?> <a href="<?php echo $link; ?>"> <?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?> </a> 
+1
source

If you have Gantry installed on Joomla 3.1, the overrides are located elsewhere. You will need to go to the plugins / system / gantry / overrides / 3.0 / 2.5 / com_content / category / blog_item.php and wrap the opening image using the sitelink code.

  <?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?> <a href="<?php echo $link; ?>"><img <?php if ($images->image_intro_caption): echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"'; endif; ?> src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/></a> 
0
source

Source: https://habr.com/ru/post/910231/


All Articles