From 7d004ef9f0b3884fc6b298ef49eea298548c9ee5 Mon Sep 17 00:00:00 2001 From: MickeyKay Date: Fri, 24 Jul 2015 16:01:24 -0700 Subject: [PATCH] Add helper function to check if post is current or descendent. --- includes/functions/theme-functions.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/includes/functions/theme-functions.php b/includes/functions/theme-functions.php index cd556cb..bd892b8 100755 --- a/includes/functions/theme-functions.php +++ b/includes/functions/theme-functions.php @@ -457,3 +457,29 @@ function trestle_image_has_size( $image_id, $image_size = null ) { return false; } + +/** + * Check if post is, or is a child of, a target post. + * + * @since 1.0.0 + * + * @param string $post_id Post ID to check. + * @param string $target_id Target post ID to check against. + * + * @return true|false + */ +function trestle_is_current_or_descendant_post( $post_id = '', $target_id = '' ) { + + // If the current post is the target post, return true. + if ( $post_id == $target_id ) { + return true; + } + + // If the current post is a descendant of the target post. + if ( in_array( $target_id, get_post_ancestors( $post_id ) ) ) { + return true; + } + + return false; + +}