Last active
August 23, 2017 13:41
-
-
Save SusanRamsey/6dfd6bad3630374f8e5a70ff0ab24a0c to your computer and use it in GitHub Desktop.
Add a New Template to display posts from one category
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 | |
/** | |
* Template Name: Daily Template | |
* Description: Used as a page template to show page contents, followed by a loop | |
* through the "Daily" category | |
*/ | |
// Add our custom loop | |
add_action( 'genesis_loop', 'cd_goh_loop' ); | |
function cd_goh_loop() { | |
$args = array( | |
'category_name' => 'daily', // replace with your category slug | |
'orderby' => 'post_date', | |
'order' => 'DESC', | |
'posts_per_page'=> '1', // overrides posts per page in theme settings | |
); | |
$loop = new WP_Query( $args ); | |
if( $loop->have_posts() ) { | |
// loop through posts | |
while( $loop->have_posts() ): $loop->the_post(); | |
echo '<h4>' . get_the_title() . '</h4>'; | |
echo '<p>' . get_the_date() . '</p>'; | |
echo '<p>' . the_content() . '</p>'; | |
echo '</div>'; | |
endwhile; | |
} | |
wp_reset_postdata(); | |
} | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment