Custom Book Reviews Archive Page
I wanted an archive page for my book reviews that showed, for each book, its front cover and an excerpt of the review.
<?php
/**
* Template Name: Book Reviews Template
* Description: Used as a page template to show page contents, followed by a loop
* through the Book Review (book-review) Category
*/
add_action('genesis_loop', 'zoia_book_reviews_loop');
function zoia_book_reviews_loop() {
$args = array(
'category_name' => 'book-review', // category slug
'order_by' => 'post_date',
'order' => 'DESC',
'posts_per_page' => '10',
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
while ($loop->have_posts() ): $loop->the_post();
echo '<div class="book-review-line">';
echo '<div class="one-sixth first book-review-bookcover">';
if(has_post_thumbnail()) {
echo '<a href="' . get_permalink() . '">';
the_post_thumbnail('medium');
echo '</a>';
} else {
echo ' ';
}
echo '</div>';
$summary = get_the_excerpt();
$summary = str_replace('Buy from Amazon', '', $summary);
echo '<div class="three-sixths">';
echo '<h4><a href="' . get_permalink() . '">' . get_the_title() . '</a></h4>';
echo '<p>' . $summary . '</p>';
echo '</div>';
echo '</div>';
endwhile;
}
wp_reset_postdata();
}
genesis();
?>