Ansico-CPT/ansico-cpt-and-taxonomies/templates/single-cpt.php

80 lines
4 KiB
PHP
Raw Normal View History

2026-04-16 18:48:19 +00:00
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
get_header();
$post_type = get_post_type();
$settings = function_exists( 'ansico_cptax' ) ? ansico_cptax()->get_cpt_template_settings( $post_type ) : array();
?>
<main id="primary" class="site-main ansico-cpt-single" style="max-width:900px;margin:40px auto;padding:0 20px;">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header" style="margin-bottom:24px;">
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php if ( ! empty( $settings['single_show_meta'] ) ) : ?>
<p class="entry-meta" style="color:#666;margin-top:8px;">
<?php echo esc_html( get_the_date() ); ?>
<?php if ( post_type_supports( $post_type, 'author' ) ) : ?>
· <?php echo esc_html( get_the_author() ); ?>
<?php endif; ?>
</p>
<?php endif; ?>
<?php if ( ! empty( $settings['single_show_featured'] ) && has_post_thumbnail() ) : ?>
<div class="entry-thumbnail" style="margin:20px 0;"><?php the_post_thumbnail( 'large' ); ?></div>
<?php endif; ?>
</header>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php if ( ! empty( $settings['single_show_terms'] ) ) : ?>
<?php $taxonomies = get_object_taxonomies( $post_type, 'objects' ); ?>
<?php if ( ! empty( $taxonomies ) ) : ?>
<section class="ansico-tax-terms" style="margin-top:30px;">
<h2><?php esc_html_e( 'Taxonomies', 'ansico-cpt-and-taxonomies' ); ?></h2>
<?php foreach ( $taxonomies as $taxonomy_name => $taxonomy_obj ) : ?>
<?php $terms = get_the_terms( get_the_ID(), $taxonomy_name ); ?>
<?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) : ?>
<p><strong><?php echo esc_html( $taxonomy_obj->labels->name ?? $taxonomy_name ); ?>:</strong>
<?php echo esc_html( implode( ', ', wp_list_pluck( $terms, 'name' ) ) ); ?>
</p>
<?php endif; ?>
<?php endforeach; ?>
</section>
<?php endif; ?>
<?php endif; ?>
<?php
if ( ! empty( $settings['single_show_custom_fields'] ) ) :
$custom = get_post_custom( get_the_ID() );
$ansico_fields = array_filter(
$custom,
function ( $key ) {
return 0 === strpos( $key, 'ansico_' );
},
ARRAY_FILTER_USE_KEY
);
if ( ! empty( $ansico_fields ) ) :
?>
<section class="ansico-custom-fields" style="margin-top:30px;">
<h2><?php esc_html_e( 'Details', 'ansico-cpt-and-taxonomies' ); ?></h2>
<ul>
<?php foreach ( $ansico_fields as $key => $values ) : ?>
<?php
$display_value = is_array( $values ) ? implode( ', ', array_map( 'wp_strip_all_tags', $values ) ) : wp_strip_all_tags( (string) $values );
if ( '' === trim( $display_value ) ) {
continue;
}
?>
<li><strong><?php echo esc_html( ucwords( str_replace( array( 'ansico_', '_' ), array( '', ' ' ), $key ) ) ); ?>:</strong> <?php echo esc_html( $display_value ); ?></li>
<?php endforeach; ?>
</ul>
</section>
<?php endif; endif; ?>
</article>
<?php endwhile; endif; ?>
</main>
<?php get_footer(); ?>