Archived topic
Would love to profoundly customize my search results page.
9 replies · Started by Alicia on March 11, 2022
Hello!
I'm trying to get my search results to look like this page:
https://dharmacomics.leahpearlman.com/comic-category/in-the-flesh/
I've already tried with the block element, but I need to add custom fields to my query. And also add more HTML.
It there a way to do this with a hook element?
Hi there,
the Block Element - Content Template supports Custom Fields, and if need be you can include a HTML block within it.
But looking at the example - what exactly is it your missing ?
The image I'm using isn't the featured image. It's the image uploaded for the comic via custom field. I've learned from the error of my ways: USE featured image already built into WordPress. But, it's too late, there are over 700 comics. It's easier to add the custom field.
That's ok.
If you use a Block Element the dynamic data supports custom fields ( aka Post Meta ).
So for example you can set the background image of a container using one:
https://docs.generatepress.com/article/dynamic-data/#dynamic-background
Or if you use the GP Dynamic Image Block it too can use a Post Meta field:
https://docs.generatepress.com/article/dynamic-blocks/#featured-image
I'm still confused. The content I'm trying to show is a custom post type called comic. I'm using ACF for the image upload. I can't see a way to choose a custom post type with the two options above.
OK - so do you currently have your Search Results displaying the CPT ?
Hi David!
I went old school and creating a custom search template file in the theme. From there, I was able to do exactly what I needed. If there was another way around this, would love to know.
This is what I love so much about GeneratePress! I'm able to do some really geeky template stuff or hook things in. Thanks for such an amazing theme!
Glad to hear that - and it sounds like the most appropriate solution for your need.
The Block Element - Content Template would not define the custom search template or the query args for specifying the post type.
It simply replaces the Template Part which GP would have requested using its generate_do_template_part function as seen here in our archive templates including search.php:
When you set a Block Element - Content Templates Display Rules, it will unhook the themes template part and hook itself in.
Yes! I used the block element to replace the content on the 404 page. Excellent!!
Awesome - glad to hear that :)