PluginProbe ʕ •ᴥ•ʔ
Author Website Templates – Create Writer, Author & Publisher Websites Easily / 1.1.5
Author Website Templates – Create Writer, Author & Publisher Websites Easily v1.1.5
trunk 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9
author-website-templates / build / blocks / author-pro / reviews / render.php
author-website-templates / build / blocks / author-pro / reviews Last commit date
block.json 5 months ago index.asset.php 5 months ago index.js 5 months ago render.php 5 months ago
render.php
117 lines
1 <?php
2 /**
3 * Render Reviews [Author Pro] Block
4 */
5
6 $block_id = isset($attributes['blockId']) ? $attributes['blockId'] : '';
7 if (empty($block_id)) {
8 $block_id = 'author-pro-reviews-' . uniqid();
9 }
10
11 $anchor = isset($attributes['anchor']) ? $attributes['anchor'] : '';
12 $element_id = !empty($anchor) ? $anchor : $block_id;
13
14 $section_title = isset($attributes['sectionTitle']) ? $attributes['sectionTitle'] : 'What Readers Say';
15 $posts_to_show = isset($attributes['postsToShow']) ? $attributes['postsToShow'] : 3;
16 $order = isset($attributes['order']) ? $attributes['order'] : 'DESC';
17
18 $bg_color = isset($attributes['bgColor']) ? $attributes['bgColor'] : '#0f172a';
19 $card_bg_color = isset($attributes['cardBgColor']) ? $attributes['cardBgColor'] : 'rgba(255, 255, 255, 0.1)';
20 $accent_color = isset($attributes['accentColor']) ? $attributes['accentColor'] : '#ea580c';
21 $text_color = isset($attributes['textColor']) ? $attributes['textColor'] : '#d1d5db';
22 $author_color = isset($attributes['authorColor']) ? $attributes['authorColor'] : '#ffffff';
23
24 $padding_top = isset($attributes['paddingTop']) ? $attributes['paddingTop'] : 96;
25 $padding_bottom = isset($attributes['paddingBottom']) ? $attributes['paddingBottom'] : 96;
26
27 // Dynamic CSS
28 $custom_css = "
29 #{$element_id} {
30 background-color: {$bg_color} !important;
31 }
32 #{$element_id} .awt-review-card {
33 background-color: {$card_bg_color} !important;
34 border-color: rgba(255, 255, 255, 0.05);
35 }
36 #{$element_id} .awt-stars {
37 color: {$accent_color} !important;
38 }
39 #{$element_id} .awt-review-text {
40 color: {$text_color} !important;
41 }
42 #{$element_id} .awt-review-author {
43 color: {$author_color} !important;
44 }
45 ";
46
47 $style = "padding-top: {$padding_top}px; padding-bottom: {$padding_bottom}px;";
48
49 $wrapper_attributes = get_block_wrapper_attributes([
50 'class' => 'awt-author-pro-reviews relative',
51 'style' => $style,
52 'id' => $element_id
53 ]);
54
55 // Query Arguments
56 $args = array(
57 'post_type' => 'book_reviews',
58 'posts_per_page' => $posts_to_show,
59 'post_status' => 'publish',
60 'order' => $order,
61 'orderby' => 'date',
62 );
63
64 $selected_book_id = isset($attributes['selectedBookId']) ? $attributes['selectedBookId'] : '0';
65
66 if ($selected_book_id && $selected_book_id !== '0') {
67 $args['meta_query'] = array(
68 array(
69 'key' => '_rswpbs_reviewed_book',
70 'value' => $selected_book_id,
71 'compare' => '='
72 )
73 );
74 }
75
76 $reviews_query = new WP_Query($args);
77 ?>
78
79 <?php if (!empty($custom_css)) : ?>
80 <style><?php echo $custom_css; ?></style>
81 <?php endif; ?>
82
83 <section <?php echo $wrapper_attributes; ?>>
84 <div class="awt-container text-center">
85 <?php if ($section_title): ?>
86 <h2 class="text-3xl font-serif font-bold mb-12 text-white"><?php echo esc_html($section_title); ?></h2>
87 <?php endif; ?>
88
89 <?php if ($reviews_query->have_posts()) : ?>
90 <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 text-left">
91 <?php while ($reviews_query->have_posts()) : $reviews_query->the_post();
92 $rating = get_post_meta(get_the_ID(), '_rswpbs_rating', true);
93 $rating = $rating ? intval($rating) : 5;
94 $reviewer_name = get_post_meta(get_the_ID(), '_rswpbs_reviewer_name', true) ?: get_the_title();
95 $content = get_the_content();
96 if (empty($content)) {
97 $content = get_the_excerpt();
98 }
99 ?>
100 <div class="awt-review-card p-8 rounded-xl border backdrop-blur-sm">
101 <div class="awt-stars mb-4 text-sm">
102 <?php for ($i = 1; $i <= 5; $i++) {
103 echo ($i <= $rating) ? '�
104 ' : '';
105 } ?>
106 </div>
107 <p class="awt-review-text italic mb-6">"<?php echo wp_trim_words(esc_html(strip_tags($content)), 30, '...'); ?>"</p>
108 <div class="awt-review-author font-bold text-sm">- <?php echo esc_html($reviewer_name); ?></div>
109 </div>
110 <?php endwhile; wp_reset_postdata(); ?>
111 </div>
112 <?php else : ?>
113 <p class="text-gray-400 italic"><?php _e('No reviews found.', 'author-website-templates'); ?></p>
114 <?php endif; ?>
115 </div>
116 </section>
117