Created
July 25, 2014 12:32
-
-
Save anonymous/24cada3a79838a7b7267 to your computer and use it in GitHub Desktop.
Current Category Recent Posts
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
//* Recent Posts Widget Filtered by Current Category | |
add_filter( 'widget_posts_args', 'my_widget_posts_args'); | |
function my_widget_posts_args($args) { | |
if ( is_category() ) { // Adds the category parameter in the query if we display a category | |
$cat = get_queried_object(); | |
return array( | |
'posts_per_page' => 10, // The number of posts shown | |
'no_found_rows' => true, | |
'post_status' => 'publish', | |
'ignore_sticky_posts' => true, | |
'cat' => $cat -> term_id // The current category ID | |
); | |
} | |
else { // Keeps the normal behaviour if we are not in category context | |
return $args; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment