94 lines
4.5 KiB
PHP
94 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* 图片附件页模板
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$system_tools = class_exists('AKSRT_Settings')
|
|
? AKSRT_Settings::get_system_tools_settings()
|
|
: ['close_attachment_page' => true];
|
|
|
|
if (!empty($system_tools['close_attachment_page'])) {
|
|
$attachment_id = get_queried_object_id();
|
|
$parent_id = (int) wp_get_post_parent_id($attachment_id);
|
|
$redirect_url = $parent_id > 0 ? get_permalink($parent_id) : home_url('/');
|
|
|
|
wp_safe_redirect($redirect_url, 301);
|
|
exit;
|
|
}
|
|
|
|
get_header();
|
|
|
|
$attachment_id = get_queried_object_id();
|
|
$parent_id = (int) wp_get_post_parent_id($attachment_id);
|
|
$image_url = wp_get_attachment_url($attachment_id);
|
|
$image_alt = trim((string) get_post_meta($attachment_id, '_wp_attachment_image_alt', true));
|
|
$image_caption = wp_get_attachment_caption($attachment_id);
|
|
$image_title = get_the_title($attachment_id);
|
|
$parent_title = $parent_id > 0 ? get_the_title($parent_id) : '';
|
|
?>
|
|
|
|
<main id="main-content" class="container page-content-default aksrt-image-page" tabindex="-1">
|
|
<div class="content-wrap">
|
|
<div class="content-layout content-layout--no-sidebar">
|
|
<div class="content-layout__primary">
|
|
<?php while (have_posts()) : the_post(); ?>
|
|
<article class="article main-bg theme-box box-body radius8 main-shadow aksrt-image-attachment">
|
|
<div class="article-header theme-box clearfix relative">
|
|
<h1 class="article-title">
|
|
<a href="<?php the_permalink(); ?>"><?php echo esc_html($image_title); ?></a>
|
|
</h1>
|
|
<?php if ($parent_id > 0) : ?>
|
|
<div class="em09 muted-3-color aksrt-image-attachment__parent">
|
|
<?php esc_html_e('所属内容:', 'aksrt'); ?>
|
|
<a href="<?php echo esc_url(get_permalink($parent_id)); ?>"><?php echo esc_html($parent_title); ?></a>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="wp-posts-content" data-nav="posts">
|
|
<?php if ($image_url) : ?>
|
|
<figure class="aksrt-image-attachment__figure">
|
|
<a href="<?php echo esc_url($image_url); ?>" class="item-thumbnail fit-cover" target="_blank" rel="noopener noreferrer">
|
|
<?php echo wp_get_attachment_image($attachment_id, 'full', false, ['class' => 'fit-cover', 'alt' => $image_alt !== '' ? $image_alt : $image_title]); ?>
|
|
</a>
|
|
<?php if ($image_caption) : ?>
|
|
<figcaption class="muted-2-color em09"><?php echo esc_html($image_caption); ?></figcaption>
|
|
<?php endif; ?>
|
|
</figure>
|
|
<?php endif; ?>
|
|
|
|
<?php if (get_the_content() !== '') : ?>
|
|
<div class="aksrt-image-attachment__content">
|
|
<?php the_content(); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="text-center post-actions aksrt-image-attachment__actions">
|
|
<?php if ($image_url) : ?>
|
|
<a href="<?php echo esc_url($image_url); ?>" class="action action-share" target="_blank" rel="noopener noreferrer">
|
|
<i class="fas fa-image" aria-hidden="true"></i>
|
|
<span><?php esc_html_e('查看原图', 'aksrt'); ?></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
<?php if ($parent_id > 0) : ?>
|
|
<a href="<?php echo esc_url(get_permalink($parent_id)); ?>" class="action action-favorite">
|
|
<i class="fas fa-arrow-left" aria-hidden="true"></i>
|
|
<span><?php esc_html_e('返回文章', 'aksrt'); ?></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</article>
|
|
<?php endwhile; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php
|
|
get_footer();
|