fictioneer/single-fcn_story.php

144 lines
4.0 KiB
PHP
Raw Normal View History

2023-01-21 01:31:34 +01:00
<?php
/**
* Custom Post Type: Story
*
* Shows the details a single story.
*
* @package WordPress
* @subpackage Fictioneer
* @since 1.0
* @see partials/_story-header.php
* @see partials/_story-footer.php
*/
2023-06-13 11:31:44 +02:00
// Setup
2024-05-09 23:42:51 +02:00
$post_id = $args['post_id'] ?? get_the_ID();
$post = get_post( $post_id );
$password_required = post_password_required();
2024-08-12 02:42:45 +02:00
$cover_position = get_theme_mod( 'story_cover_position', 'top-left-overflow' );
2024-08-12 02:42:45 +02:00
// Wrapper classes
$wrapper_classes = [];
if ( $cover_position === 'top-left-overflow' ) {
$wrapper_classes[] = '_no-padding-top';
}
// Header
get_header(
null,
array(
'type' => 'fcn_story',
'no_index' => get_post_meta( $post_id, 'fictioneer_story_hidden', true ) ? 1 : 0
)
2023-06-13 11:31:44 +02:00
);
?>
2023-01-21 01:31:34 +01:00
<main id="main" class="main story <?php echo get_option( 'fictioneer_enable_checkmarks' ) ? '' : '_no-checkmarks'; ?>">
<?php do_action( 'fictioneer_main', 'story' ); ?>
2024-08-12 02:42:45 +02:00
<div class="main__wrapper <?php echo implode( ' ', $wrapper_classes ); ?>">
2024-05-09 23:42:51 +02:00
<?php
2024-05-17 17:12:19 +02:00
do_action( 'fictioneer_main_wrapper' );
2024-05-09 23:42:51 +02:00
// Setup
2024-05-17 17:12:19 +02:00
$story_id = $post_id;
2024-05-09 23:42:51 +02:00
$story = fictioneer_get_story_data( $story_id );
$epub_name = sanitize_file_name( strtolower( get_the_title() ) );
$this_breadcrumb = [ $story['title'], get_the_permalink() ];
$password_note = fictioneer_get_content_field( 'fictioneer_story_password_note', $story_id );
$cover_position = get_theme_mod( 'story_cover_position', 'top-left-overflow' );
2023-01-21 01:31:34 +01:00
2024-05-09 23:42:51 +02:00
// Arguments for hooks and templates/etc.
$hook_args = array(
'story_data' => $story,
'story_id' => $story_id,
'password_required' => $password_required
2024-05-09 23:42:51 +02:00
);
?>
2023-01-21 01:31:34 +01:00
2024-05-09 23:42:51 +02:00
<article id="post-<?php echo $story_id; ?>" class="story__article" data-id="<?php echo $story_id; ?>" data-age-rating="<?php echo strtolower( $story['rating'] ); ?>">
2023-01-21 01:31:34 +01:00
2024-05-09 23:42:51 +02:00
<?php
// Render article header
get_template_part( 'partials/_story-header', null, $hook_args );
2023-01-21 01:31:34 +01:00
2024-05-09 23:42:51 +02:00
// Hook after header
do_action( 'fictioneer_story_after_header', $hook_args );
?>
2024-08-12 02:42:45 +02:00
<section class="story__summary"><?php
if ( $password_required ) {
2024-05-09 23:42:51 +02:00
if ( $password_note ) {
echo '<div class="story__password-note infobox">' . $password_note . '</div>';
}
2024-05-09 23:42:51 +02:00
if ( get_option( 'fictioneer_show_protected_excerpt' ) ) {
echo '<p class="story__forced-excerpt">' . fictioneer_get_forced_excerpt( $story_id, 512 ) . '</p>';
}
2024-05-09 23:42:51 +02:00
}
if (
in_array( $cover_position, ['float-left', 'float-right'] ) &&
2024-05-09 23:42:51 +02:00
has_post_thumbnail( $story_id ) &&
! get_post_meta( $story_id, 'fictioneer_story_no_thumbnail', true )
) {
echo fictioneer_get_story_page_cover(
$hook_args['story_data'],
array( 'classes' => '_in-content _' . $cover_position )
);
}
the_content();
?></section>
2024-05-09 23:42:51 +02:00
<?php
// Renders copyright notice, tags, actions, and chapters
do_action( 'fictioneer_story_after_content', $hook_args );
2023-01-21 01:31:34 +01:00
2024-05-09 23:42:51 +02:00
// Render footer partial
get_template_part( 'partials/_story-footer', null, $hook_args );
?>
2023-01-21 01:31:34 +01:00
2024-05-09 23:42:51 +02:00
</article>
2023-01-21 01:31:34 +01:00
2024-05-09 23:42:51 +02:00
<?php do_action( 'fictioneer_story_after_article', $hook_args ); ?>
2023-01-21 01:31:34 +01:00
</div>
2023-01-21 01:31:34 +01:00
</main>
<?php
// Footer arguments
$footer_args = array(
'post_type' => 'fcn_story',
'post_id' => $story_id,
'breadcrumbs' => array(
[fcntr( 'frontpage' ), get_home_url()]
)
);
// Add stories list breadcrumb (if set)
$stories_page_id = intval( get_option( 'fictioneer_stories_page', -1 ) ?: -1 );
2023-01-21 01:31:34 +01:00
if ( $stories_page_id > 0 ) {
$stories_page_title = trim( get_the_title( $stories_page_id ) );
2023-01-21 01:31:34 +01:00
$stories_page_title = empty( $stories_page_title ) ? __( 'Stories', 'fictioneer' ) : $stories_page_title;
$footer_args['breadcrumbs'][] = array(
$stories_page_title,
fictioneer_get_assigned_page_link( 'fictioneer_stories_page' )
2023-01-21 01:31:34 +01:00
);
}
// Add current breadcrumb
$footer_args['breadcrumbs'][] = $this_breadcrumb;
// Get footer with breadcrumbs
get_footer( null, $footer_args );
?>