Split index template into normal and advanced variants

This commit is contained in:
Tetrakern 2024-04-23 01:22:19 +02:00
parent ba4e7ac611
commit 340b665345
5 changed files with 175 additions and 15 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

170
singular-index-advanced.php Normal file
View File

@ -0,0 +1,170 @@
<?php
/**
* Template Name: Index (Advanced)
*
* @package WordPress
* @subpackage Fictioneer
* @since 5.14.0
*/
?>
<?php
// Setup
$post_id = get_the_ID();
// Header
get_header();
// Query all stories
$args = array(
'post_type' => 'fcn_story',
'post_status' => ['publish'],
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'name',
'update_post_term_cache' => false, // Improve performance
'no_found_rows' => true // Improve performance
);
$stories = new WP_Query( $args );
// Sort stories
$sorted_stories = [];
if ( $stories->have_posts() ) {
// Loop through posts...
foreach ( $stories->posts as $story ) {
// Skip hidden
if ( get_post_meta( $story->ID, 'fictioneer_story_hidden', true ) ) {
continue;
}
// Relevant data
$title = trim( fictioneer_get_safe_title( $story->ID, 'story_index' ) );
$first_char = strtolower( mb_substr( $title, 0, 1, 'UTF-8' ) );
// Normalize for numbers and other non-alphabetical characters
if ( is_numeric( $first_char ) ) {
$first_char = '#'; // Group under '#'
}
// Add index if necessary
if ( ! isset( $sorted_stories[ $first_char ] ) ) {
$sorted_stories[ $first_char ] = [];
}
$sorted_stories[ $first_char ][] = array(
'id' => $story->ID,
'title' => $title,
'link' => get_post_meta( $story->ID, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $story->ID ),
'date' => get_the_date( $story->ID ),
'total_words' => absint( get_post_meta( $story->ID, 'fictioneer_story_total_word_count', true ) ?? 0 ),
'rating' => get_post_meta( $story->ID, 'fictioneer_story_rating', true ),
'status' => get_post_meta( $story->ID, 'fictioneer_story_status', true )
);
}
// Sort by index
ksort( $sorted_stories );
}
// Last key
end( $sorted_stories );
$last_key = key( $sorted_stories );
reset( $sorted_stories );
?>
<main id="main" class="main singular index">
<div class="observer main-observer"></div>
<?php do_action( 'fictioneer_main' ); ?>
<div class="main__background polygon polygon--main background-texture"></div>
<div class="main__wrapper">
<?php do_action( 'fictioneer_main_wrapper' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
// Setup
$title = fictioneer_get_safe_title( $post_id, 'singular' );
$this_breadcrumb = [ $title, get_the_permalink() ];
?>
<article id="singular-<?php echo $post_id; ?>" class="singular__article padding-left padding-right padding-top padding-bottom">
<header class="singular__header hidden">
<h1 class="singular__title"><?php echo $title; ?></h1>
</header>
<section class="singular__content content-section"><?php the_content(); ?></section>
<section class="index-letters">
<?php foreach ( $sorted_stories as $index => $stories ) : ?>
<a href="<?php echo esc_attr( "#letter-{$index}" ); ?>" class="index-letters__letter"><?php echo strtoupper( $index ); ?></a>
<?php if ( $last_key !== $index ) : ?>
<span class="index-letters__separator">&bull;</span>
<?php endif; ?>
<?php endforeach; ?>
</section>
<?php foreach ( $sorted_stories as $index => $stories ) : ?>
<section class="glossary">
<h2 id="<?php echo esc_attr( "letter-{$index}" ); ?>"><?php echo strtoupper( $index ); ?></h2>
<div class="glossary__columns">
<?php foreach ( $stories as $story ) : ?>
<div class="glossary__entry">
<div class="glossary__entry-head">
<a href="<?php echo $story['link']; ?>" class="glossary__entry-name _full"><?php
echo $story['title'];
?></a>
</div>
<div class="glossary__entry-body">
<div class="glossary__entry-description">
<span class="glossary__entry-meta-item"><?php echo $story['status']; ?></span>
<span class="glossary__entry-meta-item"><?php printf( __( '%s Words', 'Index item.', 'fictioneer' ), number_format_i18n( $story['total_words'] ) ); ?></span>
<span class="glossary__entry-meta-item"><?php echo $story['rating']; ?></span>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</section>
<?php endforeach; ?>
<footer class="singular__footer"><?php do_action( 'fictioneer_singular_footer' ); ?></footer>
</article>
<?php endwhile; ?>
</div>
</main>
<?php
// Footer arguments
$footer_args = array(
'post_type' => 'page',
'post_id' => $post_id,
'breadcrumbs' => array(
[fcntr( 'frontpage' ), get_home_url()]
)
);
// Add current breadcrumb
$footer_args['breadcrumbs'][] = $this_breadcrumb;
// Get footer with breadcrumbs
get_footer( null, $footer_args );
?>

View File

@ -57,11 +57,7 @@ if ( $stories->have_posts() ) {
$sorted_stories[ $first_char ][] = array(
'id' => $story->ID,
'title' => $title,
'link' => get_post_meta( $story->ID, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $story->ID ),
'date' => get_the_date( $story->ID ),
'total_words' => absint( get_post_meta( $story->ID, 'fictioneer_story_total_word_count', true ) ?? 0 ),
'rating' => get_post_meta( $story->ID, 'fictioneer_story_rating', true ),
'status' => get_post_meta( $story->ID, 'fictioneer_story_status', true )
'link' => get_post_meta( $story->ID, 'fictioneer_story_redirect_link', true ) ?: get_permalink( $story->ID )
);
}
@ -127,13 +123,6 @@ reset( $sorted_stories );
echo $story['title'];
?></a>
</div>
<div class="glossary__entry-body">
<div class="glossary__entry-description">
<span class="glossary__entry-meta-item"><?php echo $story['status']; ?></span>
<span class="glossary__entry-meta-item"><?php printf( __( '%s Words', 'Index item.', 'fictioneer' ), number_format_i18n( $story['total_words'] ) ); ?></span>
<span class="glossary__entry-meta-item"><?php echo $story['rating']; ?></span>
</div>
</div>
</div>
<?php endforeach; ?>

View File

@ -20,6 +20,8 @@
}
&__entry {
display: grid;
gap: .25rem;
font-size: var(--fs-dxs);
line-height: 1.3;
@ -28,7 +30,6 @@
justify-content: space-between;
gap: 1rem;
font-family: var(--ff-heading);
margin-bottom: 0.25rem;
}
&-name {