Add CSS modifier class to list items if password protected

This commit is contained in:
Tetrakern 2024-02-06 14:18:37 +01:00
parent 56d04b7f00
commit 5ae01e8f15
5 changed files with 84 additions and 35 deletions

View File

@ -22,6 +22,7 @@ defined( 'ABSPATH' ) OR exit;
// Setup
$title = fictioneer_get_safe_title( $post->ID );
$story_id = get_post_meta( $post->ID, 'fictioneer_chapter_story', true );
$story_post = get_post( $story_id );
$story_unpublished = get_post_status( $story_id ) !== 'publish';
$story_data = $story_id ? fictioneer_get_story_data( $story_id, false ) : null; // Does not refresh comment count!
$chapter_rating = get_post_meta( $post->ID, 'fictioneer_chapter_rating', true );
@ -150,7 +151,15 @@ $show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_chapter_cards' )
<?php if ( ! empty( $story_id ) && ! empty( $story_data ) ) : ?>
<ol class="card__link-list cell-list">
<li class="card__link-list-item">
<?php
// Extra classes
$list_item_classes = [];
if ( ! empty( $story_post->post_password ) ) {
$list_item_classes[] = '_password';
}
?>
<li class="card__link-list-item <?php echo implode( ' ', $list_item_classes ); ?>">
<div class="card__left text-overflow-ellipsis">
<i class="fa-solid fa-caret-right"></i>
<a href="<?php the_permalink( $story_id ); ?>" class="card__link-list-link"><?php

View File

@ -115,7 +115,15 @@ if ( empty( $description ) ) {
<?php if ( ! empty( $items ) ) : ?>
<ol class="card__link-list cell-list">
<?php foreach ( $items as $item ) : ?>
<li class="card__link-list-item">
<?php
// Extra classes
$list_item_classes = [];
if ( ! empty( $item->post_password ) ) {
$list_item_classes[] = '_password';
}
?>
<li class="card__link-list-item <?php echo implode( ' ', $list_item_classes ); ?>">
<div class="card__left text-overflow-ellipsis">
<i class="fa-solid fa-caret-right"></i>
<a href="<?php the_permalink( $item->ID ); ?>" class="card__link-list-link"><?php

View File

@ -121,18 +121,29 @@ $is_sticky = FICTIONEER_ENABLE_STICKY_CARDS &&
$chapters = new WP_Query( $chapter_query_args );
?>
<?php foreach ( $chapters->posts as $chapter ) : ?>
<li class="card__link-list-item">
<?php
// Chapter title
$list_title = get_post_meta( $chapter->ID, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
if ( empty( $list_title ) ) {
$chapter_title = fictioneer_get_safe_title( $chapter->ID );
} else {
$chapter_title = $list_title;
}
// Extra classes
$list_item_classes = [];
if ( ! empty( $chapter->post_password ) ) {
$list_item_classes[] = '_password';
}
?>
<li class="card__link-list-item <?php echo implode( ' ', $list_item_classes ); ?>">
<div class="card__left text-overflow-ellipsis">
<i class="fa-solid fa-caret-right"></i>
<a href="<?php the_permalink( $chapter->ID ); ?>" class="card__link-list-link"><?php
$list_title = get_post_meta( $chapter->ID, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
if ( empty( $list_title ) ) {
echo fictioneer_get_safe_title( $chapter->ID );
} else {
echo $list_title;
}
echo $chapter_title;
?></a>
</div>
<div class="card__right">

View File

@ -146,11 +146,13 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
$search_list = array_reverse( $story['chapter_ids'] );
foreach ( $search_list as $chapter_id ) {
$chapter_post = get_post( $chapter_id );
if ( get_post_meta( $chapter_id, 'fictioneer_chapter_hidden', true ) ) {
continue;
}
$chapter_list[] = $chapter_id;
$chapter_list[] = $chapter_post;
break; // Only one needed
}
@ -203,33 +205,40 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
</div>
<ol class="card__link-list _small cell-list">
<?php foreach ( $chapter_list as $chapter_id ) : ?>
<?php foreach ( $chapter_list as $chapter ) : ?>
<?php
// Chapter title
$list_title = get_post_meta( $chapter_id, 'fictioneer_chapter_list_title', true );
$list_title = get_post_meta( $chapter->ID, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
if ( empty( $list_title ) ) {
$chapter_title = fictioneer_get_safe_title( $chapter_id );
$chapter_title = fictioneer_get_safe_title( $chapter->ID );
} else {
$chapter_title = $list_title;
}
// Extra classes
$list_item_classes = [];
if ( ! empty( $chapter->post_password ) ) {
$list_item_classes[] = '_password';
}
// Chapter excerpt
$chapter_excerpt = fictioneer_get_forced_excerpt( $chapter_id, 768 );
$chapter_excerpt = fictioneer_get_forced_excerpt( $chapter->ID, 768 );
?>
<li class="card__link-list-item">
<li class="card__link-list-item <?php echo implode( ' ', $list_item_classes ); ?>">
<div class="card__left text-overflow-ellipsis">
<i class="fa-solid fa-caret-right"></i>
<a href="<?php the_permalink( $chapter_id ); ?>" class="card__link-list-link"><?php
<a href="<?php the_permalink( $chapter->ID ); ?>" class="card__link-list-link"><?php
echo $chapter_title;
?></a>
</div>
<div class="card__right">
<?php
echo fictioneer_shorten_number( fictioneer_get_word_count( $chapter_id ) );
echo fictioneer_shorten_number( fictioneer_get_word_count( $chapter->ID ) );
echo '<span class="separator-dot">&#8196;&bull;&#8196;</span>';
echo get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter_id )
echo get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter->ID )
?>
</div>
</li>

View File

@ -146,11 +146,13 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
$search_list = array_reverse( $story['chapter_ids'] );
foreach ( $search_list as $chapter_id ) {
$chapter_post = get_post( $chapter_id );
if ( get_post_meta( $chapter_id, 'fictioneer_chapter_hidden', true ) ) {
continue;
}
$chapter_list[] = $chapter_id;
$chapter_list[] = $chapter_post;
if ( count( $chapter_list ) > 1 ) {
break; // Max two
@ -204,27 +206,37 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
</div>
<ol class="card__link-list _small cell-list">
<?php foreach ( $chapter_list as $chapter_id ) : ?>
<li class="card__link-list-item">
<?php foreach ( $chapter_list as $chapter ) : ?>
<?php
// Chapter title
$list_title = get_post_meta( $chapter->ID, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
if ( empty( $list_title ) ) {
$chapter_title = fictioneer_get_safe_title( $chapter->ID );
} else {
$chapter_title = $list_title;
}
// Extra classes
$list_item_classes = [];
if ( ! empty( $chapter->post_password ) ) {
$list_item_classes[] = '_password';
}
?>
<li class="card__link-list-item <?php echo implode( ' ', $list_item_classes ); ?>">
<div class="card__left text-overflow-ellipsis">
<i class="fa-solid fa-caret-right"></i>
<a href="<?php the_permalink( $chapter_id ); ?>" class="card__link-list-link"><?php
// Chapter title
$list_title = get_post_meta( $chapter_id, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
if ( empty( $list_title ) ) {
echo fictioneer_get_safe_title( $chapter_id );
} else {
echo $list_title;
}
<a href="<?php the_permalink( $chapter->ID ); ?>" class="card__link-list-link"><?php
echo $chapter_title;
?></a>
</div>
<div class="card__right">
<?php
echo fictioneer_shorten_number( fictioneer_get_word_count( $chapter_id ) );
echo fictioneer_shorten_number( fictioneer_get_word_count( $chapter->ID ) );
echo '<span class="separator-dot">&#8196;&bull;&#8196;</span>';
echo get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter_id )
echo get_the_date( FICTIONEER_LATEST_UPDATES_LI_DATE, $chapter->ID )
?>
</div>
</li>