Initial import of the bdmurphy Bookshelf work: the bd-bookshelf theme, bd-bookshelf-plugin, bd-bookshelfhelper and bd-simpleemail plugins, plus the specification documents, mockups and release archives.
152 lines
7.3 KiB
PHP
152 lines
7.3 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: All Books
|
|
*
|
|
* @package BD_Murphy
|
|
*/
|
|
|
|
get_header();
|
|
?>
|
|
|
|
<div class="page-container with-sidebar">
|
|
<div class="page-content">
|
|
<div class="books-container">
|
|
<header class="page-header">
|
|
<h1 class="page-title"><?php esc_html_e('Books', 'bd-bookshelf'); ?></h1>
|
|
<?php
|
|
if (function_exists('bdm_series_exist') && bdm_series_exist()) {
|
|
printf(
|
|
'<a href="%s" class="browse-series-link">%s</a>',
|
|
esc_url(home_url('/series/')),
|
|
esc_html__('Browse by Series', 'bd-bookshelf')
|
|
);
|
|
}
|
|
?>
|
|
</header>
|
|
|
|
<div class="books-list">
|
|
<?php
|
|
if (have_posts()) :
|
|
while (have_posts()) :
|
|
the_post();
|
|
setup_postdata($post);
|
|
$book_id = get_the_ID();
|
|
|
|
$cover_url = '';
|
|
if (has_post_thumbnail($book_id)) {
|
|
$cover_url = get_the_post_thumbnail_url($book_id, 'book-cover');
|
|
}
|
|
|
|
$title = esc_html(get_the_title());
|
|
|
|
$author = 'B.D. Murphy';
|
|
if (class_exists('BD_BookShelfHelper')) {
|
|
$author = BD_BookShelfHelper::get_pen_name($book_id);
|
|
}
|
|
|
|
$ratings = array();
|
|
$amazon = get_post_meta($book_id, 'amazon_rating', true);
|
|
$goodreads = get_post_meta($book_id, 'goodreads_rating', true);
|
|
if ($amazon) $ratings['amazon'] = $amazon;
|
|
if ($goodreads) $ratings['goodreads'] = $goodreads;
|
|
|
|
$blurb = '';
|
|
$excerpt = get_post_field('post_excerpt', $book_id);
|
|
if ($excerpt) {
|
|
$blurb = $excerpt;
|
|
} else {
|
|
$content = get_post_field('post_content', $book_id);
|
|
$blurb = wp_trim_words($content, 25, '...');
|
|
}
|
|
|
|
$series = null;
|
|
$terms = get_the_terms($book_id, 'series');
|
|
if ($terms && !is_wp_error($terms)) {
|
|
$series = array(
|
|
'name' => $terms[0]->name,
|
|
'slug' => $terms[0]->slug,
|
|
);
|
|
}
|
|
?>
|
|
<article class="book-entry" id="book-<?php the_ID(); ?>" <?php post_class(); ?>>
|
|
<div class="book-entry-cover">
|
|
<?php
|
|
if ($cover_url) {
|
|
printf('<img src="%s" alt="%s" loading="lazy">', esc_url($cover_url), esc_attr($title));
|
|
} else {
|
|
printf('<img src="%s" alt="%s">', esc_url(get_stylesheet_directory_uri() . '/assets/images/default-cover.png'), esc_attr__('Book cover', 'bd-bookshelf'));
|
|
}
|
|
?>
|
|
</div>
|
|
<div class="book-entry-details">
|
|
<?php if ($series) : ?>
|
|
<span class="book-series-label">
|
|
<a href="<?php echo esc_url(home_url('/series/' . $series['slug'])); ?>">
|
|
<?php printf(esc_html__('Part of %s', 'bd-bookshelf'), esc_html($series['name'])); ?>
|
|
</a>
|
|
</span>
|
|
<?php endif; ?>
|
|
|
|
<h2 class="book-title"><?php the_title(); ?></h2>
|
|
<p class="book-author"><?php echo esc_html($author); ?></p>
|
|
|
|
<?php if (!empty($ratings)) : ?>
|
|
<div class="book-ratings">
|
|
<?php if (!empty($ratings['amazon'])) : ?>
|
|
<span class="rating amazon">Amazon: <?php echo esc_html($ratings['amazon']); ?></span>
|
|
<?php endif; ?>
|
|
<?php if (!empty($ratings['goodreads'])) : ?>
|
|
<span class="rating goodreads">Goodreads: <?php echo esc_html($ratings['goodreads']); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="book-format-toggle" role="tablist" aria-label="<?php esc_attr_e('Format selection', 'bd-bookshelf'); ?>">
|
|
<button class="format-btn active" data-format="ebook" role="tab" aria-selected="true"><?php esc_html_e('Ebook', 'bd-bookshelf'); ?></button>
|
|
<button class="format-btn" data-format="paperback" role="tab"><?php esc_html_e('Paperback', 'bd-bookshelf'); ?></button>
|
|
<button class="format-btn" data-format="hardback" role="tab"><?php esc_html_e('Hardback', 'bd-bookshelf'); ?></button>
|
|
</div>
|
|
|
|
<div class="book-retailer-links">
|
|
<?php
|
|
$retailers = array('amazon' => 'Amazon', 'apple' => 'Apple Books', 'barnes' => 'Barnes & Noble', 'kobo' => 'Kobo', 'google' => 'Google Play');
|
|
foreach ($retailers as $key => $name) {
|
|
$url = get_post_meta($book_id, 'ebook_url_' . $key, true);
|
|
if ($url) {
|
|
printf(
|
|
'<a href="%s" class="retailer-link retailer-%s" target="_blank" rel="noopener noreferrer">%s</a>',
|
|
esc_url($url),
|
|
esc_attr($key),
|
|
esc_html($name)
|
|
);
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
<p class="book-blurb"><?php echo wp_kses_post($blurb); ?></p>
|
|
</div>
|
|
</article>
|
|
<?php
|
|
endwhile;
|
|
wp_reset_postdata();
|
|
else :
|
|
?>
|
|
<p class="no-books"><?php esc_html_e('No books available yet.', 'bd-bookshelf'); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<aside class="page-sidebar">
|
|
<?php if (is_active_sidebar('home-sidebar')) : ?>
|
|
<div class="home-sidebar">
|
|
<?php dynamic_sidebar('home-sidebar'); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</aside>
|
|
</div>
|
|
|
|
<?php
|
|
get_footer();
|