Last active
February 2, 2018 19:20
-
-
Save uzielweb/d011bde5eddd19c52dde5bf413962655 to your computer and use it in GitHub Desktop.
An override for search results to show images in article results . put in /templates/your_template/html/com_search/search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Joomla.Site | |
* @subpackage com_search | |
* | |
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | |
* @license GNU General Public License version 2 or later; see LICENSE.txt | |
*/ | |
defined('_JEXEC') or die; | |
$db = JFactory::getDBO(); | |
$db->setQuery("SELECT * FROM #__content ORDER BY created DESC"); | |
$articles = $db->loadObjectList(); | |
?> | |
<dl class="search-results<?php echo $this->pageclass_sfx; ?>"> | |
<?php foreach ($this->results as $count=>$result) : ?> | |
<div class="item-result"> | |
<dt class="result-title"> | |
<?php echo $this->pagination->limitstart + $result->count . '. '; ?> | |
<?php if ($result->href) : ?> | |
<a href="<?php echo JRoute::_($result->href); ?>"<?php if ($result->browsernav == 1) : ?> target="_blank"<?php endif; ?>> | |
<?php // $result->title should not be escaped in this case, as it may ?> | |
<?php // contain span HTML tags wrapping the searched terms, if present ?> | |
<?php // in the title. ?> | |
<?php echo $result->title; ?> | |
</a> | |
<?php else : ?> | |
<?php // see above comment: do not escape $result->title ?> | |
<?php echo $result->title; ?> | |
<?php endif; ?> | |
</dt> | |
<?php if ($result->section) : ?> | |
<dd class="result-category"> | |
<span class="small<?php echo $this->pageclass_sfx; ?>"> | |
(<?php echo $this->escape($result->section); ?>) | |
</span> | |
</dd> | |
<?php endif; ?> | |
<dd class="result-text"> | |
<?php | |
foreach ($articles as $article) { | |
$article_href[$count] = 'index.php?option=com_content&view=article&id=' . $article->id . ':' . $article->alias . '&catid=' . $article->catid; | |
if ($article_href[$count] == $result->href) { | |
$article_images[$count] = json_decode($article->images); | |
//Para pegar a primeira imagem em qualquer parte de um texto dos artigos | |
preg_match('/(?<!_)src=([\'"])?(.*?)\\1/', $article->introtext.$article->fulltext, $matches); | |
$image_in_article[$count] = $matches[2]; | |
if ($image_in_article[$count]) { | |
$theimage[$count] = $image_in_article[$count]; | |
} | |
elseif (($article_images[$count]->image_intro) and (empty($article_images[$count]->image_fulltext) or empty($image_in_article[$count]))) { | |
$theimage[$count] = $article_images[$count]->image_intro; | |
} | |
elseif (($article_images[$count]->image_fulltext) and (empty($article_images[$count]->image_intro) or empty($image_in_article[$count]))) { | |
$theimage[$count] = $article_images[$count]->image_fulltext; | |
} | |
elseif ($image_in_article[$count] and (empty($article_images[$count]->image_fulltext) or empty($article_images[$count]->image_intro))) { | |
$theimage[$count] = $image_in_article[$count]; | |
} | |
echo '<div class="article_image_search"><a href="'.JRoute::_($result->href).'"><img src="'.$theimage[$count].'" alt="'.$article->title.'" /></a></div>'; | |
} | |
} | |
?> | |
<?php echo $result->text; ?> | |
</dd> | |
<?php if ($this->params->get('show_date')) : ?> | |
<dd class="result-created<?php echo $this->pageclass_sfx; ?>"> | |
<?php echo JText::sprintf('JGLOBAL_CREATED_DATE_ON', $result->created); ?> | |
</dd> | |
<?php endif; ?> | |
</div> | |
<?php endforeach; ?> | |
</dl> | |
<div class="pagination"> | |
<?php echo $this->pagination->getPagesLinks(); ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment