Add option to show story header on Story Page template

This commit is contained in:
Tetrakern 2024-05-09 23:11:21 +02:00
parent fb42bcf88b
commit f77414413e
3 changed files with 47 additions and 6 deletions

View File

@ -397,7 +397,7 @@ Pages work the same as always in WordPress, just with some additional fields and
| :-- | :-: | :--
| Short Name | String | Shortened name of the page required for custom tabs in stories.
| Filter & Search ID | String | Custom identifier to be used with plugin. Does nothing on its own.
| Story ID | String | ID of a story post. Only used by the "Story Page" page template.
| Story ID | String | ID of a story post. Only used by the "Story Page/Mirror" page templates.
## Shared Options

View File

@ -2989,7 +2989,7 @@ function fictioneer_save_chapter_metaboxes( $post_id ) {
add_action( 'save_post', 'fictioneer_save_chapter_metaboxes' );
// =============================================================================
// ADVANCED META FIELDS
// EXTRA META FIELDS
// =============================================================================
/**
@ -3011,7 +3011,7 @@ function fictioneer_add_extra_metabox() {
add_action( 'add_meta_boxes', 'fictioneer_add_extra_metabox' );
/**
* Render advanced metabox
* Render extra metabox
*
* @since 5.7.4
*
@ -3095,10 +3095,19 @@ function fictioneer_render_extra_metabox( $post ) {
'fictioneer_template_story_id',
array(
'label' => _x( 'Story Id', 'Page story ID meta field label.', 'fictioneer' ),
'description' => __( 'Used only by the "Story Page" template.', 'fictioneer' )
'description' => __( 'Used by the "Story Page/Mirror" templates.', 'fictioneer' )
)
);
}
// Checkbox: Show story template header
if ( current_user_can( 'manage_options' ) ) {
$output['fictioneer_template_show_story_header'] = fictioneer_get_metabox_checkbox(
$post,
'fictioneer_template_show_story_header',
__( 'Show story template header', 'fictioneer' )
);
}
}
// Story blogs
@ -3295,6 +3304,16 @@ function fictioneer_save_extra_metabox( $post_id ) {
}
}
// Checkbox: Show story template header
if (
isset( $_POST['fictioneer_template_show_story_header'] ) &&
$post_type === 'page' &&
current_user_can( 'manage_options' )
) {
$fields['fictioneer_template_show_story_header'] =
fictioneer_sanitize_checkbox( $_POST['fictioneer_template_show_story_header'] );
}
// Story blogs
if ( isset( $_POST['fictioneer_post_story_blogs'] ) && $post_type === 'post' ) {
$story_blogs = fictioneer_explode_list( $_POST['fictioneer_post_story_blogs'] );

View File

@ -13,6 +13,13 @@
// Setup
$post_id = get_the_ID();
$story_id = get_post_meta( $post_id, 'fictioneer_template_story_id', true );
$story_id = fictioneer_validate_id( $story_id, 'fcn_story' );
$render_story_header = get_post_meta( $post_id, 'fictioneer_template_show_story_header', true );
if ( ! $story_id ) {
$render_story_header = false;
}
// Header
get_header();
@ -27,7 +34,7 @@ get_header();
<div class="main__background polygon polygon--main background-texture"></div>
<div class="main__wrapper">
<div class="main__wrapper <?php echo $render_story_header ? '_no-padding' : ''; ?>">
<?php do_action( 'fictioneer_main_wrapper' ); ?>
@ -39,7 +46,22 @@ get_header();
$this_breadcrumb = [ $title, get_the_permalink() ];
?>
<article id="singular-<?php echo $post_id; ?>" class="singular__article padding-left padding-right padding-top padding-bottom">
<article id="singular-<?php echo $post_id; ?>" class="singular__article padding-left padding-right padding-bottom <?php echo $render_story_header ? '' : 'padding-top'; ?>">
<?php
// Render story header
if ( $render_story_header ) {
get_template_part(
'partials/_story-header',
null,
array(
'story_data' => fictioneer_get_story_data( $story_id ),
'story_id' => $story_id,
'context' => 'shortcode'
)
);
}
?>
<section class="singular__content content-section"><?php the_content(); ?></section>