Hi all. Trying to get the tag to use the images inside blog posts when searched. I've got the <perch:showall> tag on, but none of the ID's seem to have the image URL. How do I find this? Or if it doesn't exist, how do I create a place for an image that the search function can find and use?

Use The Image In A Blog Post In Search Results
- dosa
- Thread is marked as Resolved.
-
-
Any word on this anyone?
-
I don't think it's available in this context. If you can't see it when use perch:showall, it's not there. The Blog app search handler is what determines what fields are made available in the blog search results.
-
Where to I put the show all tag? I've tried a few spots, but I don't see anything.
What if I add an element CMS editors can add to a post that I reference specifically for the search thumbnail. Where would that new region need to go to get it under the search?
-
Where to I put the show all tag? I've tried a few spots, but I don't see anything.
You would add it to your search results template.
If you really need to make all the Blog post fields available in search result, there are workarounds. I'll go over one:
Add conditional tags to separate the search results based on the source:
HTMLAdd a Perch Layout include and pass the result URL as a Layout variable:
Create /perch/templates/layouts/blog_search_result.php and filter the posts using the result URL:
Create the template /perch/templates/blog/post_search_result.html and include any Blog post field you want.
-
Thank you very much for this detailed explainer! I'll will try it out and confirm here soon.
-
I am missing something here. For the search page, here is the call for the results currently:
So where do I add the "post_search_template" I've created? You're suggesting the "perch_blog_custom" element, I've got all the other pieces lined up, but I'm not sure how to do the filtering now. Does the above need to be combined with this below?
To confirm, I've made the "post_search_result.html" page in the templates/blog folder, which looks like this...
Code- <!-- <perch:showall> -->
- <perch:before>
- <h1>Search results for “<perch:search id="search_key" />”</h1>
- <perch:if exists="paging">
- <p><perch:search id="total" /> results</p>
- </perch:if>
- <ul>
- </perch:before>
- <perch:if id="result_source" value="PerchBlog">
- <!--* Search result from the Blog app *-->
- <perch:layout path="global/blog_search_result" url="<perch:search id="result_url">">
- <perch:else>
- <!--* Everything else *-->
- </perch:if>
- <perch:after>
- </ul>
- <perch:if exists="paging">
- <div class="paging">
- Page <perch:search id="current_page" /> of <perch:search id="number_of_pages" />
- <perch:if exists="not_first_page">
- <a href="<perch:search id="prev_url" encode="false" />">Previous</a>
- </perch:if>
- <perch:if exists="not_last_page">
- <a href="<perch:search id="next_url" encode="false" />">Next</a>
- </perch:if>
- </div>
- </perch:if>
- </perch:after>
- <perch:noresults>
- <perch:if exists="search_key">
- <h1>Search results for “<perch:search id="search_key" />”</h1>
- <perch:else />
- <h1>Search</h1>
- </perch:if>
- <perch:if exists="search_key">
- <p>Sorry, there are no results for “<perch:search id="search_key" />”.</p>
- </perch:if>
- </perch:noresults>
And finally the "blog_search_result", which is in the templates/layouts/global folder looks like this:
Code- <li class="<perch:search id="perch_item_odd" />">
- <h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
- <perch:if exists="result_excerpt"><p class="excerpt">…<perch:search id="result_excerpt" encode="false" />…</p></perch:if>
- <p><a href="<perch:search id="result_url" />">
- <perch:if exists="result_pageNavText">
- <perch:search id="result_pageNavText" />
- <perch:else />
- <perch:search id="result_url" />
- </perch:if>
- </a></p>
- </li>
-
My comment included the path for each template ^^!
The function perch_content_search() uses the template templates/search/search-result.html by default. I'll assume you are using that.
With the search-result.html template you output the HTML for regular search results. However, when the search result source is the Blog app you use a Perch Layout include to output the search result item. Perch Layouts are PHP files. So the following:
Includes the PHP file templates/layouts/blog_search_result.php. Inside this file you use the function perch_blog_custom() to output the blog search result. This function renders another HTML template. The template you render with this function has to be placed in the directory templates/blog/ like all your other Blog app templates.
In other words, if it's a regular search result:
perch_content_search() -> templates/search/search-result.html
If the search result source is the Blog app:
perch_content_search() -> templates/search/search-result.html -> templates/layouts/blog_search_result.php (which uses perch_blog_custom()) -> templates/blog/post_search_result.html
-
Getting closer. Everything matches your notes, but the results still are not showing.
- What is the 'post_search_result.html' page supposed to look like? Just like the search-result.html?
- I'm limiting the search to /community (which we call our Blog) so all results all blog-only (which we want). But the results are showing in the regular layout from the search-result.html template. With some testing, I see it's pulling in the post_search_result.php layout, but it's stopping there.
- Using Perch Runway 2.8.29 ......does that mean I need ending slashes somewhere?
My search-result.html page includes:
Code- <li class="<perch:search id="perch_item_odd" />">
- <perch:if id="result_source" value="PerchBlog">
- <!--* Search result from the Blog app *-->
- <perch:layout path="blog_search_result" url="<perch:search id="result_url">">
- <perch:else>
- <h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
- <perch:if exists="result_excerpt"><p class="excerpt">…<perch:search id="result_excerpt" encode="false" />…</p></perch:if>
- <p><a href="<perch:search id="result_url" />">
- <perch:if exists="result_pageNavText">
- <perch:search id="result_pageNavText" />
- <perch:else />
- <perch:search id="result_url" />
- </perch:if>
- </a></p>
- </li>
- </perch:if>
- <perch:after>
- </ul>
My blog_search_result.php page:
My post_search_result.html page (with some yellow styling so I can see which is which):
Code- <li style="background:yellow;" class="<perch:search id="perch_item_odd" />">
- <h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
- <perch:if exists="result_excerpt"><p class="excerpt">…<perch:search id="result_excerpt" encode="false" />…</p></perch:if>
- <p><a href="<perch:search id="result_url" />">
- <perch:if exists="result_pageNavText">
- <perch:search id="result_pageNavText" />
- <perch:else />
- <perch:search id="result_url" />
- </perch:if>
- </a></p>
- </li>
-
What is the 'post_search_result.html' page supposed to look like? Just like the search-result.html?
It should be used to output the search results of a single blog post.
I'm limiting the search to /community (which we call our Blog) so all results all blog-only (which we want). But the results are showing in the regular layout from the search-result.html template. With some testing, I see it's pulling in the post_search_result.php layout, but it's stopping there.
If you want to limit the search results to the Blog app, you would use the apps option:
Using Perch Runway 2.8.29 ......does that mean I need ending slashes somewhere?
Yes. Your template tags need to be self-closing />.
-
Ok. The Blog app filter works the same as the from-path, but I've switched it anyway.
Got it on the self-closing now. Now the search-results.html has:
Code- <ul>
- </perch:before>
- <li class="<perch:search id="perch_item_odd" />">
- <perch:if id="result_source" value="PerchBlog" />
- <!--* Search result from the Blog app *-->
- <perch:layout path="blog_search_result" url="<perch:search id="result_url" />">
- <perch:else>
- <h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
- <perch:if exists="result_excerpt" /><p class="excerpt">…<perch:search id="result_excerpt" encode="false" />…</p></perch:if>
- <p><a href="<perch:search id="result_url" />">
- <perch:if exists="result_pageNavText" />
- <perch:search id="result_pageNavText" />
- <perch:else />
- <perch:search id="result_url" />
- </perch:if>
- </a></p>
- </li>
- </perch:if>
- <perch:after>
- </ul>
...but the results show like this (with blank spots where the post_search_result.html elements should be). Seems like the layout is not pulling in the right data.
Code- <li class="">
- <li style="background:yellow;" class="">
- <h2><a href=""></a></h2>
- <p><a href="">
- </a></p>
- </li>
- <h2><a href="/community/2016-crm-winner">2016 CRM Winner</a></h2>
- <p class="excerpt">2016 CRM Winner <em class="keyword">Winner</em>.
- This is a highly anticipated industry award for the best-of-the-best in the CRM assembled annually by noted CRM author and analyst.…</p>
- <p><a href="/community/2016-crm-winner">
- /community/2016-crm-winner
- </a></p>
- </li>
From the "background:yellow" style, I can see the layout surrounding HTML. But why isn't is showing any perch:search elements? This is the post_search_result.html layout, which is being called on the search-result.html page via the perch:layout, then the layout calls up the post_search_result template which looks like this:
Code- <li style="background:yellow;" class="<perch:search id="perch_item_odd" />">
- <h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
- <perch:if exists="result_excerpt" /><p class="excerpt">…<perch:search id="result_excerpt" encode="false" />…</p></perch:if>
- <p><a href="<perch:search id="result_url" />">
- <perch:if exists="result_pageNavText" />
- <perch:search id="result_pageNavText" />
- <perch:else />
- <perch:search id="result_url" />
- </perch:if>
- </a></p>
- </li>
But as you can see at the top, the content is blank.
-
...but the results show like this (with blank spots where the post_search_result.html elements should be). Seems like the layout is not pulling in the right data.
You are outputting <li> twice per a single search result item. Once from inside search-result.html and again from inside post_search_result.html.
-
Thanks for that HTML correction. But the elements from the post_search_result.html page aren't connecting, they are still blank.
This:
Code- <h2><a href="<perch:search id="result_url" />"><perch:search id="result_title" /></a></h2>
- <perch:if exists="result_excerpt" /><p class="excerpt">…<perch:search id="result_excerpt" encode="false" />…</p></perch:if>
- <p><a href="<perch:search id="result_url" />">
- <perch:if exists="result_pageNavText" />
- <perch:search id="result_pageNavText" />
- <perch:else />
- <perch:search id="result_url" />
- </perch:if>
- </a></p>
Is resulting in this:
-
Your post_search_result.html template is like any other blog template. You need to use the perch:blog name space and you need to use the actual blog post fields. You are no longer in the context of the search there.
So you would use:
-
Awesome!! That is was the missing piece. Because the "post_search_result.html" was part of the search, I assumed it was perch:search, not perch:blog. Now I can pull in anything from the post.html and similar template - sweet.
I really appreciate your persistence in helping me Hussein. Thanks!
-
Happy to help!
-
hi hus_hmd - I'm back on this search since I've migrated the site to a new server, now using Perch 3 Runway. And the key, I have moved the location and renamed from /community to /about/newsroom
So now, of course using the same templates as above, I'm getting empty results. I imagine it's simply missing a connection somewhere with the rename, but I can't seem to find it. Hope you can help!
Here's a summary:
templates/search/search-results.html
Code- <perch:before>
- <h4>You searched for "<perch:search id="search_key" />" <perch:if exists="paging">and we found <perch:search id="total" /> results:</perch:if></h4>
- <ul>
- </perch:before>
- <li class="<perch:search id="perch_item_odd" />">
- <perch:if id="result_source" value="PerchBlog" />
- <!--* Search result from the Blog app *-->
- <perch:layout path="blog_search_result" url="<perch:search id="result_url" />">
- </perch:if>
- </li>
- <perch:after>
- </ul>
- <perch:if exists="paging">
- <div class="paging">
- Page <perch:search id="current_page" /> of <perch:search id="number_of_pages" />
- <perch:if exists="not_first_page">
- <a href="<perch:search id="prev_url" encode="false" />">Previous</a>
- </perch:if>
- <perch:if exists="not_last_page">
- <a href="<perch:search id="next_url" encode="false" />">Next</a>
- </perch:if>
- </div>
- </perch:if>
- </perch:after>
- <perch:noresults>
- <perch:if exists="search_key">
- <h1>Search results for “<perch:search id="search_key" />”</h1>
- <perch:else />
- <h1>Search</h1>
- </perch:if>
- <perch:if exists="search_key">
- <p>Sorry, there are no results for “<perch:search id="search_key" />”.</p>
- </perch:if>
- </perch:noresults>
templates/layouts/blog_search_result.php
templates/blog/post_search_result.html
Code- <div class="image"><a href="<perch:blog id="postURL" />"><img src="<perch:blog id="image" />" alt="<perch:blog id="postTitle" />"></a></div>
- <div class="content">
- <h2><a href="<perch:blog id="postURL" />"><perch:blog id="postTitle" /></a></h2>
- <perch:if exists="subtitle"><p><perch:blog id="subtitle" striptags="true" /></p></perch:if>
- </div>
templates/search/search-form.html
The problem is when I search, the result is blank, as if it's not finding the PerchBlog source. However, the page still shows how many results, and an empty list of all the results.
Code- <section class="newsroom newsroom-blog" id="newsroom">
- <div class="container">
- <div id="newsroom-header">
- <div id="content">
- <h1>Newsroom: Search</h1>
- </div>
- </div>
- <div id="newsroom-content">
- <h4>You searched for "test" and we found 21 results:</h4>
- <ul>
- <li class=""></li>
- <li class="odd"></li>
- <li class=""></li>
- <li class="odd"></li>
- <li class=""></li>
- <li class="odd"></li>
- <li class=""></li>
- <li class="odd"></li>
- <li class=""></li>
- <li class="odd"></li>
- <li class=""></li>
- <li class="odd"></li>
- <li class=""></li>
- <li class="odd"></li>
- </ul>
- <div class="paging">
- Page 1 of 3 <a href="/about/newsroom/search?q=test&page=2">Next</a>
- </div>
- </div>
- </div>
- </section>
Also, FYI, in the CMS Settings panel, I have the "Blog post page path" set as /newsroom/{postSlug} ....this is intentional, my client wants the links this way. Could this be throwing off the connection to the search results? Everything else is working.
-
I'd check things one by one until you find where it is not working.
(1) Turn on debug mode and check for errors
(2) Your search template is only set up to show results from the Blog app. If you get a result from another source it will output an empty <li></li>. Does the term test return any Blog results? You can restrict the search to the Blog app:
(3) Check what you're getting what expect. Output the result_url and/or showall the available variables. Is it a blog post URL like you expect?
-
Everything seems to be working, the showall has all the data, but still the <li>'s are empty. Perhaps I have the syntax wrong? I was already filtering via the apps array, but it looks like my syntax is different. (neither work though, same results)
No errors are showing in the debug mode either. It confirms the template being used. And that code is on post_search_result.html:
Code- <div class="image"><a href="<perch:blog id="postURL" />"><img src="<perch:blog id="image" />" alt="<perch:blog id="postTitle" />"></a></div>
- <div class="content">
- <h2><a href="<perch:blog id="postURL" />"><perch:blog id="postTitle" /></a></h2>
- <perch:if exists="subtitle"><p><perch:blog id="subtitle" striptags="true" /></p></perch:if>
- </div>
-