Last active
February 25, 2019 12:15
-
-
Save danbru1989/845bef6e00032fbf400cbbb305dcfa00 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 | |
/** | |
* Updates Page. | |
* | |
* @package BrubakerDesignServices\FaithForRevivalTheme | |
* @since 1.0.0 | |
* @author Dan Brubaker | |
* @link https://brubakerservices.org/ | |
* @license GPL-2.0+ | |
*/ | |
namespace BrubakerDesignServices\FaithForRevivalTheme; | |
// Replace the blog loop with custom loop. | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
add_action( 'genesis_loop', __NAMESPACE__ . '\do_custom_loop' ); | |
genesis(); | |
/** | |
* Build custom blog loop that excludes the post from the latest post section. | |
* | |
* @return void | |
*/ | |
function do_custom_loop() { | |
if ( ! is_paged() ) { | |
add_latest_post(); | |
} | |
// Run a query to get the ID of the latest post so it can be removed from the main query. | |
$exclude_post = new \WP_Query( 'posts_per_page=1' ); | |
if ( $exclude_post->have_posts() ) { | |
while ( $exclude_post->have_posts() ) { | |
$exclude_post->the_post(); | |
$exclude_post_id = get_the_id(); | |
} | |
wp_reset_postdata(); | |
} | |
global $paged; | |
$args = array( | |
'post_not_in' => array( $exclude_post_id ), | |
'post_per_page' => 6, | |
'paged' => $paged, | |
); | |
genesis_custom_loop( $args ); | |
} | |
/** | |
* Output the latest post section. | |
* | |
* @return void | |
*/ | |
function add_latest_post() { | |
$args = array( | |
'posts_per_page' => 1, | |
'no_found_rows' => true, | |
); | |
$latest_post = new \WP_Query( $args ); | |
echo 'THIS WORKS FINE.'; | |
if ( $latest_post->have_rows() ) { | |
while ( $latest_post->have_rows() ) { | |
$latest_post->the_post(); | |
echo 'THIS IS NOT WORKING!'; | |
} | |
wp_reset_postdata(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment