Skip to content

Instantly share code, notes, and snippets.

@isuke01
Last active December 19, 2022 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isuke01/738194bfa5498ae8437b070809b6855c to your computer and use it in GitHub Desktop.
Save isuke01/738194bfa5498ae8437b070809b6855c to your computer and use it in GitHub Desktop.
WP - Assign to page separated template file and extend pages status texts
<?php
add_action( 'admin_head-edit.php', 'edit_post_change_title_in_list' );
function edit_post_change_title_in_list() {
add_filter( 'display_post_states', 'use_template_as_post_state', 100, 2);
}
function use_template_as_post_state( $post_states, $post ) {
$available_templates = get_page_templates($post);
$post_template_file = get_post_meta( $post->ID, '_wp_page_template', true );
ksort( $available_templates );
// for displaying in status page tempate name
foreach ( array_keys( $available_templates ) as $template ) {
if($available_templates[ $template ] == $post_template_file) $post_states[] = __('Template: ', 'textdomain').$template;
}
// Extendfor display page archive for page-template.php
if ( $post->post_type === 'page' ) {
global $option;
if ( $option['archives-projects'] == $post->ID ) {
$post_states[] = '<small>'.__('Archive for projects','textdomain').'</small>';
}
}
return $post_states;
}
add_filter( 'template_include', 'archive_for_peojects', 99 );
function archive_for_peojects( $template ) {
global $post, $option;
if ( $post->ID == $option['archives-projects'] ) {
$new_template = locate_template( array( 'template/archive-projects.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
}
@isuke01
Copy link
Author

isuke01 commented May 31, 2017

Simple way to assign to page that you want (id is from $option['archives-projects'] or whenever you save this page ) a separated file used as template for this page.
Nice way to build special archives based on custom files, and add to option a way to assign page.

And second file is for add more info in backed for page status title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment