Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'manage_edit-page_columns', 'page_column_views' );
- add_filter( 'manage_edit-page_sortable_columns', 'page_column_views' );
- function page_column_views( $columns ) {
- $columns['page-layout'] = 'Template';
- return $columns;
- }
- add_action( 'manage_pages_custom_column', 'page_custom_column_views', 5, 2 );
- function page_custom_column_views( $column_name, $page_id ) {
- if ( $column_name === 'page-layout' ) {
- $set_template = get_post_meta( $page_id, '_wp_page_template', true );
- if ( $set_template == 'default' ) {
- echo 'Default';
- }
- else {
- $templates = get_page_templates();
- ksort( $templates );
- foreach ( array_keys( $templates ) as $template ) :
- if ( $set_template == $templates[$template] ) echo $template;
- endforeach;
- echo '<br /><small>' . $set_template . '</small>';
- }
- }
- }
- add_action( 'pre_get_posts', 'sort_pages_by_page_template' );
- function sort_pages_by_page_template( $query ) {
- if ( ! is_admin() )
- return;
- $orderby = $query->get( 'orderby');
- if( 'page-layout' == $orderby ) {
- $query->set( 'meta_key', '_wp_page_template' );
- $query->set( 'orderby', 'meta_value' );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement