From 00ed3c364110754b565075f40485475a3bb3015b Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Thu, 14 Feb 2019 17:32:39 -0500 Subject: [PATCH] Add templatesUsed function with links to respective pages --- functions.php | 104 +++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/functions.php b/functions.php index e7a970b..c2b5758 100644 --- a/functions.php +++ b/functions.php @@ -416,61 +416,61 @@ function get_county_page_children($countyPageId = false) { return $countyChildren; } -// function templates_used() { -// add_menu_page( -// __( 'Templates Used', 'textdomain' ), -// 'Templates Used', -// 'manage_options', -// 'templates-used.php', -// 'list_templates_used', -// plugins_url( '' ), -// 999 -// ); -// } -// add_action( 'admin_menu', 'templates_used' ); - -// function list_templates_used( ) { -// global $post; -// echo "

Templates Used

"; -// list_templates_by_type( 'page' ); -// list_templates_by_type( 'post' ); -// //list_templates_by_type( 'custom-post-type' ); -// } - -// function list_templates_by_type( $type = 'page' ) { +function templates_used() { + add_menu_page( + __( 'Templates Used', 'textdomain' ), + 'Templates Used', + 'manage_options', + 'templates-used.php', + 'list_templates_used', + plugins_url( '' ), + 999 + ); +} +add_action( 'admin_menu', 'templates_used' ); + +function list_templates_used( ) { + global $post; + echo "

Templates Used

"; + list_templates_by_type( 'page' ); + list_templates_by_type( 'post' ); + //list_templates_by_type( 'custom-post-type' ); +} + +function list_templates_by_type( $type = 'page' ) { -// $args = array( 'post_type' => $type, 'posts_per_page' => -1 ); -// $posts = get_posts( $args ); -// $count = 0; + $args = array( 'post_type' => $type, 'posts_per_page' => -1 ); + $posts = get_posts( $args ); + $count = 0; -// $output = ''; -// $output .= '

\''. $type .'\' List

'; + $output = ''; + $output .= '

\''. $type .'\' List

'; -// foreach ($posts as $post) { -// setup_postdata( $post ); -// if ( get_page_template_slug( $post->ID ) ) { -// if ( $count == 0 ) { -// $output .= ' Every '. $type .' not listed below has template "Default".

'; -// $output .= ' '; -// $output .= ' '; -// } -// $count++; -// $output .= ''; -// $output .= ''; -// $output .= ''; -// $output .= ''; -// $output .= ''; -// $output .= ''; -// } + foreach ($posts as $post) { + setup_postdata( $post ); + if ( get_page_template_slug( $post->ID ) ) { + if ( $count == 0 ) { + $output .= ' Every '. $type .' not listed below has template "Default".

'; + $output .= '
IDNameSlugTemplate
' . $post->ID . '' . $post->post_title . '' . $post->post_name . '' . get_page_template_slug( $post->ID ) . '
'; + $output .= ' '; + } + $count++; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + } -// } -// $output .= ''; -// $output .= '
IDNameSlugTemplate
' . $post->ID . '' . $post->post_title . '' . $post->post_name . '' . get_page_template_slug( $post->ID ) . '
'; + } + $output .= ''; + $output .= ''; -// if ( $count == 0 ) { -// $output .= ' Either there are no posts with type "' . $type . '", or none of them have custom templates set (and have the Default template). '; -// } + if ( $count == 0 ) { + $output .= ' Either there are no posts with type "' . $type . '", or none of them have custom templates set (and have the Default template). '; + } -// wp_reset_postdata(); -// echo $output; -// } \ No newline at end of file + wp_reset_postdata(); + echo $output; +} \ No newline at end of file -- 2.17.1