Last active
April 26, 2017 10:58
-
-
Save cdils/9c23ae92e304d345b308ba2e8941e350 to your computer and use it in GitHub Desktop.
This file contains 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 | |
add_action( 'pre_get_posts', 'cd_show_all_posts' ); | |
/** | |
* Show all posts on a specified archive page. | |
* | |
* @author Carrie Dils | |
* @link https://carriedils.com/genesis-archive-page/ | |
* @param object $query data | |
* | |
*/ | |
function cd_show_all_posts( $query ) { | |
if( $query->is_main_query() && !is_admin() && $query->is_post_type_archive( 'courses' ) ) { | |
$query->set( 'posts_per_page', '-1' ); | |
} | |
} | |
// Register widget area for archive ad. | |
genesis_register_sidebar( array( | |
'id' => 'archive-ad', | |
'name' => __( 'Archive Ad', 'cd' ), | |
'description' => __( 'Use this widget area to display and add on archive pages.', 'cd' ), | |
) ); | |
add_action( 'genesis_after_entry', 'cd_ad_insert' ); | |
/** | |
* Display a widget area on the archive after the 2nd post. | |
* | |
* Uses built in Loop counter to get the index (position) of the post currently being displayed. | |
* | |
* @author Carrie Dils | |
* @link https://carriedils.com/genesis-archive-page/ | |
*/ | |
function cd_ad_insert() { | |
global $wp_query; | |
if ( 1 == $wp_query->current_post ) { | |
genesis_widget_area( 'archive-ad', array( | |
'before' => '<div class="archive-ad">', | |
'after' => '</div>', | |
) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment