Last active
December 14, 2021 19:03
-
-
Save gstricklind/4ce6539c171166f8feb9 to your computer and use it in GitHub Desktop.
Genesis: Recent Posts Shortcode With Category Option
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
<? | |
/*======================================================================== | |
Custom Loop Shortcode | |
========================================================================*/ | |
add_action('init' , 'gs_init'); | |
function gs_init() { | |
add_shortcode( 'custom_post_feed', 'gs_custom_post_feed_shortcode_handler' ); | |
//[custom_post_feed category="wisdom" show="1"] | |
} | |
function gs_custom_post_feed_shortcode_handler( $atts ) { | |
extract( | |
shortcode_atts( | |
array( | |
'show' => '5', // by default show 5 | |
'category' => '', | |
), | |
$atts | |
) | |
); | |
$args = array ( | |
'post_status' => 'publish', | |
'category_name' => $category, // category slug | |
'posts_per_page' => $show, // # of posts to show | |
); | |
ob_start(); | |
// optional: remove the pagination | |
remove_action( 'genesis_after_endwhile', 'genesis_posts_nav' ); | |
// optional: and may not work for others - this simply moves the featurd images above the post title on the homepage | |
if ( is_front_page() ) { | |
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); | |
remove_action( 'genesis_entry_header', 'post_featured_image', 15 ); | |
add_action( 'genesis_entry_header', 'post_featured_image', 1 ); | |
} | |
genesis_custom_loop( wp_parse_args($query_args, $args) ); | |
$html = ob_get_clean(); | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pagination only works on archive pages, not standard pages