PluginProbe ʕ •ᴥ•ʔ
Author Website Templates – Create Writer, Author & Publisher Websites Easily / 1.1.9
Author Website Templates – Create Writer, Author & Publisher Websites Easily v1.1.9
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 / hero-book-slider / render.php
author-website-templates / build / blocks / author-pro / hero-book-slider Last commit date
block.json 1 month ago index.asset.php 1 month ago index.js 1 month ago render.php 1 month ago style-index-rtl.css 1 month ago style-index.css 1 month ago view.asset.php 1 month ago view.js 1 month ago
render.php
225 lines
1 <?php
2 /**
3 * Hero Book Slider Block Render Template.
4 *
5 * @var array $attributes Block attributes.
6 * @var array $content Block content.
7 * @var array $block Block instance.
8 */
9
10 $post_count = isset($attributes['postCount']) ? $attributes['postCount'] : 5;
11 $accent_color = isset($attributes['accentColor']) ? $attributes['accentColor'] : '#ea580c';
12 $autoplay_speed = isset($attributes['autoplaySpeed']) ? $attributes['autoplaySpeed'] : 5000;
13 $enable_autoplay = isset($attributes['enableAutoplay']) ? $attributes['enableAutoplay'] : false;
14 $enable_title_trim = isset($attributes['enableTitleTrim']) ? $attributes['enableTitleTrim'] : false;
15 $title_trim_length = isset($attributes['titleTrimLength']) ? $attributes['titleTrimLength'] : 10;
16
17 // Dynamic Color Attributes
18 $title_color = isset($attributes['titleColor']) ? $attributes['titleColor'] : '';
19 $price_color = isset($attributes['priceColor']) ? $attributes['priceColor'] : '';
20 $excerpt_color = isset($attributes['excerptColor']) ? $attributes['excerptColor'] : '';
21 $blob_color_1 = isset($attributes['blobColor1']) ? $attributes['blobColor1'] : '';
22 $blob_color_2 = isset($attributes['blobColor2']) ? $attributes['blobColor2'] : '';
23 $featured_tag_bg = isset($attributes['featuredTagBg']) ? $attributes['featuredTagBg'] : '';
24 $featured_tag_text = isset($attributes['featuredTagText']) ? $attributes['featuredTagText'] : '';
25
26 // CSS Classes & Styles Logic
27 $title_class = $title_color ? '' : 'text-primary';
28 $title_style = $title_color ? "color: {$title_color};" : '';
29
30 $price_class = $price_color ? '' : 'text-primary';
31 $price_style = $price_color ? "color: {$price_color};" : '';
32
33 $excerpt_class = $excerpt_color ? '' : 'text-secondary';
34 $excerpt_style = $excerpt_color ? "color: {$excerpt_color};" : '';
35
36 $blob1_class = $blob_color_1 ? '' : 'bg-blue-50/50';
37 $blob1_style = $blob_color_1 ? "background-color: {$blob_color_1};" : '';
38
39 $blob2_class = $blob_color_2 ? '' : 'bg-accent/5';
40 // If blobColor2 is set, use it. Otherwise use the accent color with opacity logic from before.
41 $blob2_style = $blob_color_2 ? "background-color: {$blob_color_2};" : "background-color: {$accent_color}10;";
42
43 $featured_bg_class = $featured_tag_bg ? '' : 'bg-yellow-100';
44 $featured_bg_style = $featured_tag_bg ? "background-color: {$featured_tag_bg};" : '';
45
46 $featured_text_class = $featured_tag_text ? '' : 'text-yellow-800';
47 $featured_text_style = $featured_tag_text ? "color: {$featured_tag_text};" : '';
48
49 // Logic to determine Autoplay value
50 $autoplay_val = $enable_autoplay ? $autoplay_speed : 'false';
51
52 // Wrapper Attributes
53 $wrapper_classes = ['relative', 'overflow-hidden', 'h-auto', 'min-h-[600px]', 'md:min-h-[700px]', 'lg:h-[800px]', 'flex', 'items-center', 'py-20'];
54 // Only add bg-paper if NO background color is selected via standard supports
55 if (empty($attributes['backgroundColor']) && empty($attributes['style']['color']['background'])) {
56 $wrapper_classes[] = 'bg-paper';
57 }
58 $wrapper_class_string = implode(' ', $wrapper_classes);
59
60 $wrapper_attributes = get_block_wrapper_attributes([
61 'class' => $wrapper_class_string,
62 'data-autoplay' => $autoplay_val
63 ]);
64
65 $args = array(
66 'post_type' => 'book',
67 'posts_per_page' => $post_count,
68 'post_status' => 'publish',
69 );
70
71 $book_query = new WP_Query($args);
72
73 if ($book_query->have_posts()) :
74 ?>
75 <section <?php echo $wrapper_attributes; ?>>
76 <div class="absolute top-0 right-0 w-1/2 h-full rounded-bl-[100px] -z-10 pointer-events-none <?php echo esc_attr($blob1_class); ?>" style="<?php echo esc_attr($blob1_style); ?>"></div>
77 <div class="absolute bottom-0 left-0 w-64 h-64 rounded-full blur-3xl -z-10 pointer-events-none <?php echo esc_attr($blob2_class); ?>" style="<?php echo esc_attr($blob2_style); ?>"></div>
78
79 <div class="glide hero-slider w-full h-full relative group">
80 <div class="glide__track h-full" data-glide-el="track">
81 <ul class="glide__slides h-full p-0 m-0">
82 <?php
83 while ($book_query->have_posts()) :
84 $book_query->the_post();
85 $book_id = get_the_ID();
86
87 // Price Calculation Logic
88 $raw_price = get_post_meta($book_id, '_rsbs_book_price', true);
89 $raw_sale_price = get_post_meta($book_id, '_rsbs_book_sale_price', true);
90
91 // Clean data
92 $regular_price = (float) preg_replace('/[^0-9.]/', '', $raw_price);
93 $sale_price = (float) preg_replace('/[^0-9.]/', '', $raw_sale_price);
94
95 // Linked Product Override
96 if (function_exists('rswpbs_get_linked_product')) {
97 $linked_product = rswpbs_get_linked_product();
98 if ($linked_product) {
99 $regular_price = $linked_product->get_regular_price();
100 $sale_price = $linked_product->get_sale_price();
101 }
102 }
103
104 // Logic
105 $has_sale = !empty($sale_price) && $sale_price < $regular_price && $sale_price > 0;
106 $display_price = $has_sale ? $sale_price : $regular_price;
107 $currency_symbol = function_exists('get_woocommerce_currency_symbol') ? get_woocommerce_currency_symbol() : '$';
108
109 $buy_btn_text = get_post_meta($book_id, '_rsbs_buy_btn_text', true);
110 $buy_btn_link = get_post_meta($book_id, '_rsbs_buy_btn_link', true);
111 $format_val = get_post_meta($book_id, '_rsbs_book_format', true);
112 $shortDescription = get_post_meta($book_id, '_rsbs_short_description', true);
113 ?>
114 <li class="glide__slide flex items-center h-full m-0">
115 <div class="awt-container">
116 <div class="grid grid-cols-1 lg:grid-cols-2 gap-12 items-center">
117 <div class="space-y-6">
118 <?php if ( get_post_meta( $book_id, 'is_featured', true ) ) : // Optional: Logic for featured tag if it exists, or just hardcode as in example ?>
119 <div class="inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-bold uppercase tracking-wider <?php echo esc_attr($featured_bg_class . ' ' . $featured_text_class); ?>" style="<?php echo esc_attr($featured_bg_style . $featured_text_style); ?>">
120 <i class="fas fa-star"></i> Featured
121 </div>
122 <?php else : ?>
123 <div class="inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-bold uppercase tracking-wider <?php echo esc_attr($featured_bg_class . ' ' . $featured_text_class); ?>" style="<?php echo esc_attr($featured_bg_style . $featured_text_style); ?>">
124 <i class="fas fa-star"></i> Featured
125 </div>
126 <?php endif; ?>
127
128 <div>
129 <h2 class="text-4xl md:text-5xl lg:text-6xl font-serif font-bold leading-tight mb-2">
130 <a class="hover:opacity-90 transition-opacity duration-300 <?php echo esc_attr($title_class); ?>"
131 href="<?php the_permalink(); ?>"
132 style="<?php echo esc_attr($title_style); ?>">
133 <?php
134 if ( $enable_title_trim ) {
135 echo esc_html( wp_trim_words( get_the_title(), $title_trim_length, '...' ) );
136 } else {
137 the_title();
138 }
139 ?>
140 </a>
141 </h2>
142 </div>
143 <?php
144 if ($display_price) : ?>
145 <div class="text-3xl font-serif font-bold <?php echo esc_attr($price_class); ?>" style="<?php echo esc_attr($price_style); ?>">
146 <?php echo esc_html($currency_symbol . $display_price); ?>
147 <?php if ($has_sale) : ?>
148 <span class="text-lg text-gray-400 line-through font-sans font-normal ml-2">
149 <?php echo esc_html($currency_symbol . $regular_price); ?>
150 </span>
151 <?php endif; ?>
152 </div>
153 <?php endif; ?>
154 <div class="leading-relaxed text-lg max-w-lg line-clamp-3 <?php echo esc_attr($excerpt_class); ?>" style="<?php echo esc_attr($excerpt_style); ?>">
155 <p class="leading-relaxed text-lg max-w-lg <?php echo esc_attr($excerpt_class); ?>" style="<?php echo esc_attr($excerpt_style); ?>">
156 <?php echo $shortDescription; ?></p>
157 </div>
158
159 <div class="flex flex-wrap gap-4 pt-4">
160 <?php
161 if (shortcode_exists('rswpbs_book_loop_btn')) {
162 echo do_shortcode('[rswpbs_book_loop_btn]');
163 }
164
165 echo '<a target="_blank" href="'.esc_url($buy_btn_link).'"
166 class="px-6 py-3.5 bg-white text-primary border border-gray-200 font-bold rounded hover:border-[#FF9900] hover:text-[#FF9900] transition flex items-center gap-2">'
167 . esc_html($buy_btn_text) .
168 '</a>';
169
170 $buy_links = get_post_meta($book_id, 'rswpbs_also_available_website_list', true);
171
172 if (!empty($buy_links) && is_array($buy_links)) {
173 foreach (array_slice($buy_links, 0, 2) as $link) {
174 $url = isset($link['book_url']) ? esc_url($link['book_url']) : '#';
175 $name = isset($link['website_name']) ? esc_html($link['website_name']) : 'Buy Now';
176 ?>
177 <a href="<?php echo $url; ?>" class="px-6 py-3.5 bg-white text-primary border border-gray-200 font-bold rounded hover:border-[#FF9900] hover:text-[#FF9900] transition flex items-center gap-2">
178 <?php echo $name; ?>
179 </a>
180 <?php
181 }
182 }
183 ?>
184 </div>
185 </div>
186
187 <div class="flex justify-center lg:justify-end relative">
188 <?php if (has_post_thumbnail()) : ?>
189 <img src="<?php echo get_the_post_thumbnail_url(get_the_ID(), 'large'); ?>"
190 class="w-[300px] md:w-[380px] rounded shadow-1xl border-4 border-white transform rotate-[-3deg] hover:rotate-0 transition duration-700">
191 <?php endif; ?>
192 </div>
193 </div>
194 </div>
195 </li>
196 <?php
197 endwhile;
198 wp_reset_postdata();
199 ?>
200 </ul>
201 </div>
202
203 <div data-glide-el="controls">
204 <button class="absolute top-1/2 left-4 md:left-8 transform -translate-y-1/2 w-12 h-12 rounded-full border border-gray-200 bg-white/80 backdrop-blur text-primary hover:bg-accent hover:text-white hover:border-accent transition flex items-center justify-center shadow-lg z-20 group" data-glide-dir="&lt;" style="--hover-bg: <?php echo esc_attr($accent_color); ?>">
205 <svg class="w-6 h-6" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640">
206 <path d="M169.4 297.4C156.9 309.9 156.9 330.2 169.4 342.7L361.4 534.7C373.9 547.2 394.2 547.2 406.7 534.7C419.2 522.2 419.2 501.9 406.7 489.4L237.3 320L406.6 150.6C419.1 138.1 419.1 117.8 406.6 105.3C394.1 92.8 373.8 92.8 361.3 105.3L169.3 297.3z" />
207 </svg>
208 </button>
209
210 <button class="absolute top-1/2 right-4 md:right-8 transform -translate-y-1/2 w-12 h-12 rounded-full border border-gray-200 bg-white/80 backdrop-blur text-primary hover:bg-accent hover:text-white hover:border-accent transition flex items-center justify-center shadow-lg z-20 group" data-glide-dir="&gt;" style="--hover-bg: <?php echo esc_attr($accent_color); ?>">
211 <svg class="w-6 h-6" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640">
212 <path d="M471.1 297.4C483.6 309.9 483.6 330.2 471.1 342.7L279.1 534.7C266.6 547.2 246.3 547.2 233.8 534.7C221.3 522.2 221.3 501.9 233.8 489.4L403.2 320L233.9 150.6C221.4 138.1 221.4 117.8 233.9 105.3C246.4 92.8 266.7 92.8 279.2 105.3L471.2 297.3z" />
213 </svg>
214 </button>
215 </div>
216 </div>
217 </section>
218 <?php
219 else :
220 ?>
221 <p><?php esc_html_e('No books found.', 'author-website-templates'); ?></p>
222 <?php
223 endif;
224 ?>
225