Genesis Framework Custom Search Template which includes the custom post type and forces the different layouts available in framework.
While working on one of the theme development project using Genesis Framework. The client requested a different type of search results layout which includes the CPT (Custom Post Type) .
Here is the Solution
In Genesis Child Theme, Create the search.php file and remove the Genesis Standard Loop and write your own custom loop which includes the CPT (Custom Post Type) in my project it was Article & Videos and display the end result as needed.
Final Result Look like below image.
STEP 1 : Create Custom Search Template
Create the file named search.php in child theme directory having the below code:
Forcing The Layout – Line number 10 to 20 contains code for all layout options available, current full-width template is enabled here.
Just un-comment the layout code that you would like to use.
Custom Post Type & Order – Line number 35 contains code for post types included in desired order for the search result.
Much More You can do with above template code
- Remove The Post Information – Line no 54
- Remove The Post Featured Image – Line no 57
- Remove The Post Content – Line no 60
- Remove Post Content Nav – Line no 63 & 64
- Modify The Content Limit – Line no 67
- Modify The Content Limit Read More Link – Line no 70
- Force Excerpt Content – Line no 73
- Modify The Excerpt Limit Read More Link – Line no 76
- Remove The Post Meta Information – Line no 82 to 84
- Remove The archive Pagination – Line no 87
Before doing anything mentioned in above list you should be aware of what you are doing.
This is a great search page template! I’ve just got one issue bugging me – when allowing archive pagination (by commenting out line 87) the pagination shows up, but the pagination doesn’t work. It looks like there’s no handling of pagination built into this template.
If someone has a pagination example online that works with this code here please point me to it.
Hi! Is it possible to expand this code to have 3 different search loops, based on the post_type? We need a global search based on posts/pages only, a blog search based on posts only, and a custom search based on a custom post_type (resource).
Perhaps If statements for each based on page/post and/or page_id within the search.php? Would that work? Or maybe you may have a different approach to resolve?
Your assistance is greatly appreciated!
Deb
Yeah we can have three different search loops., but why you need that way when in single query we can search from all.
Can you please let me know so i can help you.
Hasti
The project is to have the post/page search form on the search page available from the header above the global nav (this is the one that is active). The second search form (posts only) is to be found on the blog pages next to the blog nav. The third search form is for a new custom post type (resource) to be found on an archive page to be built for that post type. This is for a resource library of assorted media to be available to visitors, but the search is separate from posts and pages in the global/blog search.
Thank you!
Excellent post