Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
sgitner

Add template as a column?

Any chance you can add teh template in use as a column — io found this snippet but it conflicts with admin columnns.

`//add column with page template name in-use

add_filter( ‘manage_pages_columns’, ‘page_column_views’ );
add_action( ‘manage_pages_custom_column’, ‘page_custom_column_views’, 5, 2 );
function page_column_views( $defaults )
{
$defaults[‘page-layout’] = __(‘Template’);
return $defaults;
}
function page_custom_column_views( $column_name, $id )
{
if ( $column_name === ‘page-layout’ ) {
$set_template = get_post_meta( get_the_ID(), ‘_wp_page_template’, true );
if ( $set_template == ‘default’ ) {
echo ‘Default’;
}
$templates = get_page_templates();
ksort( $templates );
foreach ( array_keys( $templates ) as $template ) :
if ( $set_template == $templates[$template] ) echo $template;
endforeach;
}
}

6 years, 11 months ago
Stefan van den Dungen Gronovius
Developer

Hi there,

We already made a column called ‘Page Template’ which does exactly the same and even is sortable, filterable and inline editable. So I suggest if you use that one.

But you should also be able to use this code if you like with our plugin. When you add this code to your theme or plugin, it is not directly added to the overview page like the default behaviour in WordPress. The reason is that our plugin takes of that control. So you have to add this column to the overview using our plugin. The column is located in the ‘default’ group.

Please let me know if anything is unclear.

6 years, 11 months ago

You must be logged in to reply to this topic.