Last active
December 19, 2022 10:52
-
-
Save isuke01/738194bfa5498ae8437b070809b6855c to your computer and use it in GitHub Desktop.
WP - Assign to page separated template file and extend pages status texts
This file contains 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 | |
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; | |
} |
This file contains 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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.