Joomla 3.1 intro image as read more link

蓝咒 提交于 2019-12-12 02:52:14

问题


In joomla 3.1 I edited in this file \components\com_content\views\featured\tmpl\default_item.php

<?php if (isset($images->image_intro) && !empty($images->image_intro)) : ?>
    <?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
    <div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image"> <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; ?>

to:

<?php if (isset($images->image_intro) && !empty($images->image_intro)) : ?>
    <?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
    <div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image"><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> </div>
<?php endif; ?>`

but its not working correct, because is linking to the main page... how I can fix this, I tried everything from this, but it does not work Joomla intro image as read more link


回答1:


First of all, you should never edit a core file. Instead of editing \components\com_content\views\featured\tmpl\default_item.php, you should make a copy of the file and place it here - /templates/YOUR TEMPLATE/html/com_content/featured/default_item.php.

This will prevent Joomla from overwriting any changes when there is an update/upgrade. This is probably also why you are not seeing the change on your site. There is very likely a template override for \components\com_content\views\featured\tmpl\default_item.php already in your template folder. If there is, Joomla will use that file instead of the core file you are editing. Make your changes in your template override and it should work.




回答2:


I found the resolution:

<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); ?>"/> 

Modified to:

<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>"><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>

And now its working correct :), and thanks to Brent Friar for the template override :)



来源:https://stackoverflow.com/questions/19654706/joomla-3-1-intro-image-as-read-more-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!