Search form results showing by newest
Permalink
Hi.
Do you know how to modify the blocks/search/controllers.php file, so that the search results appear in order from the newest page? I was searching everywhere but nothing... Can You help me?
Do you know how to modify the blocks/search/controllers.php file, so that the search results appear in order from the newest page? I was searching everywhere but nothing... Can You help me?
Yes, this works. Thank You very much. I am trying to add thumbnail, but getting page attribute gives error. Maybe You can help too? :)
Call to a member function getAttribute() on null
By copying this section (Image/File), you will have all the data of your page `thumbnail` attribute. Then you will be able to use them in your HTML code.
https://github.com/shahroq/whale_c5_cheat_sheet#get-a-page-attribute...
https://github.com/shahroq/whale_c5_cheat_sheet#get-a-page-attribute...
But I want to list thumnails in search results. After use $attr = $page->getAttribute('thumbnail') I'am getting error.
Use this piece in your serach block template, in the results loop:
<?php // Image/File $attr = $r->getAttribute('thumbnail'); if ($attr) { $attrTitle = $attr->getTitle(); //echo $attrTitle; $attrURL = $attr->getURL(); //echo $attrURL; $attrDownloadURL = $attr->getDownloadURL(); //echo $attrDownloadURL; $attrForceDownloadURL = $attr->getForceDownloadURL(); //echo $attrForceDownloadURL; $attrSize = $attr->getSize(); //echo $attrSize; $attrExtension = $attr->getExtension(); //echo $attrExtension; // image thumbnail $ih = Core::make('helper/image'); $thumbSrc = $ih->getThumbnail($attr, 100, 100)->src; echo $thumbSrc; }
As I wrote earlier, I used this in my block template search (in Pixel2 called 'pixel_gruped') but recieving this error:
Call to a member function getAttribute() on null
Did you notice the $page has been substituted for $r in the first line?
Of course, the error appears using $page or $r.
When I put code after <div id="searchResults"> or <div class="searchResult"> error is not showing but, thumbnails don't show up either.
When I put code after <div id="searchResults"> or <div class="searchResult"> error is not showing but, thumbnails don't show up either.
@shahroq I tried this code in multiple locations in the results loop of my custom search block template. It returns the text URL string to the thumbnail image, but the thumbnail does not actually get displayed in the search results. Using v8. please advise.
I worked it out
about line 43
about line 43
?><div class="searchResult"> <? // Image/File $attr = $r->getAttribute('thumbnail'); if ($attr) { // make thumbnail $ih = Core::make('helper/image'); $thumbSrc = $ih->getThumbnail($attr, 100, 100)->src; ?><img src="<?=$thumbSrc?>" /> <? } ?> <h3>
You can sort the search result by different criteria in the search block controller: do_search() method. In your case adding this line before calling getPagination() method should do the trick:
\concrete\blocks\search\controller.php: do_search()
If you need more sorting options, check this cheat sheet out:
https://github.com/shahroq/whale_c5_cheat_sheet#sort-a-page-list...
P.S: And this is the reminder that tweaking the core files is not a recommended practice. You had better override the file and add the line in the overridden file.