Concrete 5.7 - Search box, Display results with thumbnails
Permalink
Hi folks!
First time writing here on formus concrete5.
I am currently building a site which would need the search results (basic search block), to display their respective thumbnails (or custom attribute).
[attached screenshot]
I tried out what was suggested on another discussion, however i guess that is relevant for the 5.6 Version only? :/
http://www.concrete5.org/community/forums/customizing_c5/adding-pag...
It is bugging me for two days now, i better ask if anyone has tackled this with the 5.7 version as well :D
Currently i have created a custom template for a searchblock.
Custom attibute set on pages is 'thumbnail'.
Code as follows for the do_search:
First time writing here on formus concrete5.
I am currently building a site which would need the search results (basic search block), to display their respective thumbnails (or custom attribute).
[attached screenshot]
I tried out what was suggested on another discussion, however i guess that is relevant for the 5.6 Version only? :/
http://www.concrete5.org/community/forums/customizing_c5/adding-pag...
It is bugging me for two days now, i better ask if anyone has tackled this with the 5.7 version as well :D
Currently i have created a custom template for a searchblock.
Custom attibute set on pages is 'thumbnail'.
Code as follows for the do_search:
if (isset($do_search) && $do_search) { if (count($results) == 0) { ?><h4 style="margin-top:32px"><?php echo t('There were no results found. Please try another keyword or phrase.')?></h4><?php } else { $tt = Core::make('helper/text'); ?><div id="searchResults"><?php foreach ($results as $r) { $currentPageBody = $this->controller->highlightedExtendedMarkup($r->getPageIndexContent(), $query); $oPage = Page::getById($r->getID()); $response = $oPage->getAttribute('thumbnail'); ?><div class="searchResult"> <img src="<?php echo $response->src ?>" /> <h3><a href="<?php echo $r->getCollectionLink()?>"><?php echo $r->getAttribute('nome_persona')?></a></h3> <p><?php if ($r->getCollectionDescription()) {
Viewing 15 lines of 29 lines. View entire code block.
We did this for 5.7 in a project and it is straightforward: Create a new viewing template for the search block. This isn't a big deal, so where are your problems exactly?
Hi,
thanks for answering.
Yeah i created a new template, however it seems like it can't read the pages IDs in order to read each thumbnail.
The above code is a portion of a new template view for the search box. (view.php)
This is the error code it shows up
So yeah i am currently out of ideas why it doesn't work.
I tried creating a new template file, and added the supposed need code in order to call and show the image thumbnail.
If you could take a look, would be great.
thanks for answering.
Yeah i created a new template, however it seems like it can't read the pages IDs in order to read each thumbnail.
The above code is a portion of a new template view for the search box. (view.php)
This is the error code it shows up
Fatal error: Call to undefined method Concrete\Core\Page\Page::getID()
So yeah i am currently out of ideas why it doesn't work.
I tried creating a new template file, and added the supposed need code in order to call and show the image thumbnail.
If you could take a look, would be great.
<?php defined('C5_EXECUTE') or die('Access Denied.'); if (isset($error)) { ?><?php echo $error?><br/><br/><?php } if (!isset($query) || !is_string($query)) { $query = ''; } ?><form action="<?php echo $view->url($resultTargetURL)?>" method="get" class="ccm-search-block-form freshnesssearch"><?php if (isset($title) && ($title !== '')) { ?><h3><?php echo h($title)?></h3><?php } if ($query === '') { ?><input name="search_paths[]" type="hidden" value="<?php echo htmlentities($baseSearchPath, ENT_COMPAT, APP_CHARSET) ?>" /><?php } elseif (isset($_REQUEST['search_paths']) && is_array($_REQUEST['search_paths'])) { foreach ($_REQUEST['search_paths'] as $search_path) {
Viewing 15 lines of 54 lines. View entire code block.
Try $r->getCollectionID() not $r->getID()
Alright we have a small improvement with that. :)
Error no longer displaying, however image is not displaying yet.
Perhaps i forgot something like the image::Helper? uhm..
EDIT::
IT NOW WORKS!!
After adjusting the getCollectionID(),
in the IMG tag, i had to call the src in a different way.
Anyhow, this is how it works:
Thanks again!!
I can now finish up this search block formatting ;)
Error no longer displaying, however image is not displaying yet.
Perhaps i forgot something like the image::Helper? uhm..
EDIT::
IT NOW WORKS!!
After adjusting the getCollectionID(),
in the IMG tag, i had to call the src in a different way.
Anyhow, this is how it works:
<?php foreach ($results as $r) { $currentPageBody = $this->controller->highlightedExtendedMarkup($r->getPageIndexContent(), $query); $oPage = Page::getById($r->getCollectionID()); //thanks pvernaglia ?> <div class="searchResult"> <img src="<?php echo ($oPage->getAttribute('thumbnail')->getRelativePath());?>" /> </div> }>
Thanks again!!
I can now finish up this search block formatting ;)
I thought I would add this complete code example for including thumbnail images in search results. This works in Concrete5 8.4.2
This code is placed at /application/blocks/search/templates/imageSearch.php
Add a search block to your page → refresh the page → (stay in edit mode) click the search block → Design & Custom Template → click the cog button → choose 'ImageSearch' from the dropdown → Save → Save the page.
You'll need to add some CSS to style it up - you may also want to change the location of the 'thumbnailImage' div in the code.
This code is placed at /application/blocks/search/templates/imageSearch.php
Add a search block to your page → refresh the page → (stay in edit mode) click the search block → Design & Custom Template → click the cog button → choose 'ImageSearch' from the dropdown → Save → Save the page.
You'll need to add some CSS to style it up - you may also want to change the location of the 'thumbnailImage' div in the code.
<?php defined('C5_EXECUTE') or die('Access Denied.'); if (isset($error)) { ?><?=$error?><br/><br/><?php } if (!isset($query) || !is_string($query)) { $query = ''; } ?><form action="<?=$view->url($resultTarget)?>" method="get" class="ccm-search-block-form"><?php if (isset($title) && ($title !== '')) { ?><h3><?=h($title)?></h3><?php } if ($query === '') { ?><input name="search_paths[]" type="hidden" value="<?=htmlentities($baseSearchPath, ENT_COMPAT, APP_CHARSET) ?>" /><?php } elseif (isset($_REQUEST['search_paths']) && is_array($_REQUEST['search_paths'])) { foreach ($_REQUEST['search_paths'] as $search_path) {
Viewing 15 lines of 67 lines. View entire code block.