Home › Forums › Support › How can I customize the "Nothing Found" layout on archive.php with Elements?
- This topic has 14 replies, 3 voices, and was last updated 7 years, 4 months ago by
Tom.
-
AuthorPosts
-
November 17, 2018 at 9:01 am #729828
Pete
How can I customize the “Nothing Found” layout on archive.php with Elements?
November 17, 2018 at 4:09 pm #729961Leo
StaffCustomer SupportHi there,
What are you looking to customize?
It should be the 404 template under Display Rule.
Let me know 🙂
November 17, 2018 at 4:13 pm #729965Pete
Nothing Found isn’t the same as the 404 page. Nothing Found appears when the URL is correct but there’s no posts in that category yet.
November 17, 2018 at 6:05 pm #729985Tom
Lead DeveloperLead DeveloperCurrently, there are no Display Rules for that, as there isn’t a condition for it inside WP.
We might be able to use a filter to display a certain element if there are no search results though. Would that work for you?
November 17, 2018 at 6:07 pm #729987Pete
That sounds worth a go, thanks.
November 17, 2018 at 7:01 pm #730008Tom
Lead DeveloperLead DeveloperSo first, create a new Element and take note of its ID.
Then you can use the filter (dependent on the kind of Element):
https://docs.generatepress.com/article/generate_layout_element_display/
https://docs.generatepress.com/article/generate_header_element_display/
https://docs.generatepress.com/article/generate_hook_element_display/So for example, if we’re doing a Header Element:
add_filter( 'generate_header_element_display', function( $display, $element_id ) { if ( 10 === $element_id && is_search() ) { global $wp_query; if ( ! $wp_query->found_posts ) { $display = true; } } return $display; }, 10, 2 );The only thing you’d need to change is the element ID (10).
November 17, 2018 at 7:03 pm #730012Pete
That’s great thanks Tom I’ll give it a try and get back to you.
November 18, 2018 at 11:33 pm #730639Pete
OK, I have this in a hook element…
add_filter( 'generate_header_element_display', function( $display, $element_id ) { if ( 80 === $element_id) { global $wp_query; if ( ! $wp_query->found_posts ) { $display = true; } } return $display; }, 10, 2 );Hook: before_main_content
Display rule: Post categoryWhat next?
November 19, 2018 at 8:08 am #731131Tom
Lead DeveloperLead DeveloperWhat that code does is set it so that Element (
80) should display on the no results page.You should add it using one of these methods: https://docs.generatepress.com/article/adding-php/
November 24, 2018 at 4:45 am #737261Pete
I’m not following exactly what to do.
November 24, 2018 at 8:11 am #737559Tom
Lead DeveloperLead Developer1. Create your Element, as you would if you could choose the “Nothing Found” page in Display Rules. Take note of the Element ID once you publish it. Leave Display Rules empty.
2. Add the above function using one of these methods: https://docs.generatepress.com/article/adding-php/
In the code, replace
10with the ID of the Element you published in step 1.Now the Element you published will appear on the Nothing Found template.
November 24, 2018 at 9:44 am #737646Pete
1. Create your Element,
A hook element?November 24, 2018 at 5:00 pm #737957Tom
Lead DeveloperLead DeveloperIt depends on what you’re trying to add to the No Results page. What exactly are you wanting to change on that page?
November 24, 2018 at 7:32 pm #738026Pete
Just the text to say something else.
November 25, 2018 at 9:22 am #738664Tom
Lead DeveloperLead DeveloperCurrently, the text for the no results page isn’t filterable.
So, you’d need to copy this file: https://github.com/tomusborne/generatepress/blob/2.2.1/no-results.php
And add it to your child theme. Make sure it keeps the same filename:
no-results.phpThen you could change the text to whatever you like.
-
AuthorPosts
- You must be logged in to reply to this topic.