Skip to content

Commit

Permalink
Load CPT template
Browse files Browse the repository at this point in the history
  • Loading branch information
FitoreGashi committed Sep 27, 2024
1 parent 975ac7a commit 4e87567
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
15 changes: 15 additions & 0 deletions rrze-faudir.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,18 @@ function shortcode_parse_atts_to_string($atts) {
}
return trim($output);
}


function load_custom_person_template($template) {
if (get_query_var('custom_person') || is_singular('custom_person')) {
$plugin_template = plugin_dir_path(__FILE__) . 'templates/single-custom_person.php';
if (file_exists($plugin_template)) {
error_log('Loading custom person template: ' . $plugin_template);
return $plugin_template;
} else {
error_log('Custom person template not found at: ' . $plugin_template);
}
}
return $template;
}
add_filter('template_include', 'load_custom_person_template', 99);
73 changes: 73 additions & 0 deletions templates/single-custom_person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
get_header();
?>

<main id="main" class="site-main">
<?php
while (have_posts()) :
the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>

<div class="entry-content">
<?php the_content(); ?>

<h2><?php _e('Additional Information', 'text-domain'); ?></h2>
<ul>
<?php
$fields = [
'person_id' => __('Person ID', 'text-domain'),
'person_name' => __('Name', 'text-domain'),
'person_email' => __('Email', 'text-domain'),
'person_telephone' => __('Telephone', 'text-domain'),
'person_given_name' => __('Given Name', 'text-domain'),
'person_family_name' => __('Family Name', 'text-domain'),
'person_title' => __('Title', 'text-domain'),
'person_pronoun' => __('Pronoun', 'text-domain'),
'person_function' => __('Function', 'text-domain'),
];

foreach ($fields as $meta_key => $label) :
$value = get_post_meta(get_the_ID(), $meta_key, true);
if (!empty($value)) :
?>
<li><strong><?php echo esc_html($label); ?>:</strong> <?php echo esc_html($value); ?></li>
<?php
endif;
endforeach;
?>
</ul>

<?php
$content_lang = get_post_meta(get_the_ID(), '_content_lang', true);
if (!empty($content_lang)) :
?>
<h2><?php _e('Content (Second Language)', 'text-domain'); ?></h2>
<div class="content-second-language">
<?php echo wp_kses_post($content_lang); ?>
</div>
<?php
endif;

$teaser_lang = get_post_meta(get_the_ID(), '_teasertext_lang', true);
if (!empty($teaser_lang)) :
?>
<h2><?php _e('Teaser Text (Second Language)', 'text-domain'); ?></h2>
<div class="teaser-second-language">
<?php echo wp_kses_post($teaser_lang); ?>
</div>
<?php
endif;
?>
</div>
</article>
<?php
endwhile;
?>
</main>

<?php
get_footer();

0 comments on commit 4e87567

Please sign in to comment.