Last active
October 5, 2017 19:11
-
-
Save patric-boehner/3f5d4cc2d69927c2acf54db4d9dd9f89 to your computer and use it in GitHub Desktop.
Change how the Genesis framework handels the else at the end of a loop when no posts are found. Genesis only provides a filter for the text, but that text also contains the main structure. This snippet removed and receates that function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Update Genesis No Post Text | |
| * | |
| * @package Child Theme | |
| * @author Patrick Boehner | |
| * @copyright Copyright (c) 2017, Patrick Boehner | |
| * @license GPL-2.0+ | |
| * | |
| */ | |
| //* Security Updates | |
| //***************************** | |
| if( !defined( 'ABSPATH' ) ) exit; | |
| //* Replace No Posts Section | |
| //***************************** | |
| remove_action( 'genesis_loop_else', 'genesis_do_noposts' ); | |
| add_action( 'genesis_loop_else', 'pb_custom_no_posts' ); | |
| function pb_custom_no_posts() { | |
| echo '<div class="entry"><div class="entry-content">'; | |
| // Output Text | |
| printf( '<p class="no-posts-message">%s</p>', apply_filters( 'genesis_noposts_text', __( 'Sorry, no content matched your criteria.', 'child-theme' ) ) ); | |
| // Output Widget Area | |
| if ( is_post_type_archive( 'pb_cpt_services' ) || is_tax( 'service-category' ) && is_active_sidebar( 'no-posts-widget' ) ) { | |
| genesis_widget_area ('no-posts-widget', array( | |
| 'before' => '<div class="no-posts-widget-area widget-area">', | |
| 'after' => '</div><!-- End of No Posts Widget Area -->',)); | |
| } | |
| echo '</div></div>'; | |
| } | |
| //* Update No Post Text | |
| //***************************** | |
| add_filter( 'genesis_noposts_text', 'pb_change_no_post_text', 10, 2 ); | |
| function pb_change_no_post_text( $text ) { | |
| if ( is_search() ) { | |
| $text = __( '<strong>Sorry, but nothing matched your search terms.</strong> Please try again with some different keywords.', 'child-theme' ); | |
| $text = $text . genesis_search_form(); | |
| } | |
| if ( is_archive() ) { | |
| $text = __( '<strong>Sorry, but I don\'t have any posts on that subject.</strong> Please try searching for something else.', 'child-theme' ); | |
| $text = $text . genesis_search_form(); | |
| } | |
| if ( is_post_type_archive( 'pb_cpt_services' ) || is_tax( 'service-category' ) ) { | |
| $text = __( '<strong>Sorry, there is nothing currently scheduled.</strong> I have new events coming all the time. If you would like to be kept up to date about availability or if you have a question, please get in touch. Let me know how I can best help you.', 'child-theme' ); | |
| // $text = $text . genesis_search_form(); | |
| } | |
| if ( is_post_type_archive( 'pb_cpt_testimonials' ) || is_tax( 'testimonial-category' ) ) { | |
| $text = __( '<strong>Sorry, there aren\'t any testimonials for this service yet.</strong> If you would like to contribute a testimonial or if you have a question please get in touch.', 'child-theme' ); | |
| } | |
| return $text; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Update Genesis No Post Text | |
| * | |
| * @package Child Theme | |
| * @author Patrick Boehner | |
| * @copyright Copyright (c) 2017, Patrick Boehner | |
| * @license GPL-2.0+ | |
| * | |
| */ | |
| //* Security Updates | |
| //***************************** | |
| if( !defined( 'ABSPATH' ) ) exit; | |
| //* Add Widget for No Posts pages | |
| //***************************** | |
| genesis_register_sidebar( array( | |
| 'id' => 'no-posts-widget', | |
| 'name' => __( 'No Services Available', 'child-theme' ), | |
| 'description'=> __( 'This widget area shows when no services are available. This widget area is meant to be used with a contact form.', 'gentleheartyoga-2016' ), | |
| ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment