Last active
December 19, 2015 09:39
-
-
Save thisislawatts/5934211 to your computer and use it in GitHub Desktop.
WordPress Dashboard. Order by Page Template
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
<?php /** | |
* | |
* Adds a Column to WordPress pages admin so you can easily see | |
* which pages are using which page template. | |
* | |
* @since 1.0 | |
*/ | |
function la_modify_page_table ( $columns ) { | |
/* Add a Page Template Column */ | |
$custom_columns = array( | |
'template' => __('Page Template', 'wordpress') | |
); | |
$columns = array_merge( $columns, $custom_columns ); | |
unset($columns['comments']); | |
return $columns; | |
} | |
add_filter('manage_pages_columns', 'la_modify_page_table'); | |
/** | |
* Register our column as sortable | |
*/ | |
function la_sortable_template_column($columns) { | |
return array_merge( $columns, array( 'template' => 'template' ) ); | |
} | |
add_filter('manage_edit-page_sortable_columns', 'la_sortable_template_column'); | |
/** | |
* | |
* Templ | |
*/ | |
function la_template_column_orderby( $query ) { | |
if (!is_admin()) return; | |
$orderby = $query->get('orderby'); | |
if ( $orderby == 'template' ) { | |
$query->set('meta_key', '_wp_page_template'); | |
$query->set('orderby', 'meta_value'); | |
} | |
} | |
add_action('pre_get_posts', 'la_template_column_orderby'); | |
/** | |
* | |
* The content for our template column | |
* | |
* | |
*/ | |
function la_modify_page_table_content( $column_name, $post_id ) { | |
/* Available Page Templates */ | |
$templates = get_page_templates(); | |
/* Template used on this page */ | |
$current_template = get_page_template_slug($post_id); | |
foreach ($templates as $label => $filename ) { | |
if ($filename == $current_template) { | |
echo "$label / $filename"; | |
return; | |
} | |
} | |
echo 'Default'; | |
} | |
add_filter('manage_pages_custom_column', 'la_modify_page_table_content', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment