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
319 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Book Carousel 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 | // Attributes |
| 11 | $post_count = isset($attributes['postCount']) ? $attributes['postCount'] : 10; |
| 12 | $columns = isset($attributes['columns']) ? $attributes['columns'] : 3; |
| 13 | $gap = isset($attributes['gap']) ? $attributes['gap'] : 32; |
| 14 | $enable_autoplay = isset($attributes['enableAutoplay']) ? $attributes['enableAutoplay'] : false; |
| 15 | $autoplay_speed = isset($attributes['autoplaySpeed']) ? $attributes['autoplaySpeed'] : 3000; |
| 16 | $enable_title_trim = isset($attributes['enableTitleTrim']) ? $attributes['enableTitleTrim'] : false; |
| 17 | $title_trim_length = isset($attributes['titleTrimLength']) ? $attributes['titleTrimLength'] : 10; |
| 18 | |
| 19 | // Content Attributes |
| 20 | $section_title = isset($attributes['sectionTitle']) ? $attributes['sectionTitle'] : 'More Books by Author'; |
| 21 | $section_subtitle = isset($attributes['sectionSubtitle']) ? $attributes['sectionSubtitle'] : 'Library'; |
| 22 | $show_section_title = isset($attributes['showSectionTitle']) ? $attributes['showSectionTitle'] : true; |
| 23 | $view_all_text = isset($attributes['viewAllText']) ? $attributes['viewAllText'] : 'View All Books'; |
| 24 | $view_all_link = isset($attributes['viewAllLink']) ? $attributes['viewAllLink'] : '/books'; |
| 25 | $show_view_all = isset($attributes['showViewAll']) ? $attributes['showViewAll'] : true; |
| 26 | |
| 27 | // Color Attributes |
| 28 | $section_bg_color = isset($attributes['sectionBgColor']) ? $attributes['sectionBgColor'] : ''; |
| 29 | $card_bg_color = isset($attributes['cardBgColor']) ? $attributes['cardBgColor'] : ''; |
| 30 | $title_color = isset($attributes['titleColor']) ? $attributes['titleColor'] : ''; |
| 31 | $author_color = isset($attributes['authorColor']) ? $attributes['authorColor'] : ''; |
| 32 | $price_color = isset($attributes['priceColor']) ? $attributes['priceColor'] : ''; |
| 33 | $accent_color = isset($attributes['accentColor']) ? $attributes['accentColor'] : ''; |
| 34 | $arrow_bg_color = isset($attributes['arrowBgColor']) ? $attributes['arrowBgColor'] : ''; |
| 35 | $arrow_icon_color = isset($attributes['arrowIconColor']) ? $attributes['arrowIconColor'] : ''; |
| 36 | |
| 37 | |
| 38 | // --- Logic for Inline Styles & Classes --- |
| 39 | |
| 40 | // 1. Section BG |
| 41 | $section_style = $section_bg_color ? 'style="background-color: ' . esc_attr($section_bg_color) . ';"' : ''; |
| 42 | $section_class = $section_bg_color ? 'py-24' : 'py-24 bg-paper'; |
| 43 | |
| 44 | // 2. Title (Section) |
| 45 | $title_style = $title_color ? 'style="color: ' . esc_attr($title_color) . ';"' : ''; |
| 46 | $title_class = $title_color ? 'awt-title text-4xl font-serif font-bold mt-2' : 'awt-title text-4xl font-serif font-bold text-primary mt-2'; |
| 47 | |
| 48 | // 3. Subtitle (Accent) |
| 49 | $subtitle_style = $accent_color ? 'style="color: ' . esc_attr($accent_color) . ';"' : ''; |
| 50 | // Note: Default for subtitle was text-accent. |
| 51 | // If custom accent is set, use it. If not, use text-accent class. |
| 52 | $subtitle_class = $accent_color ? 'awt-subtitle font-bold text-xs uppercase tracking-widest' : 'awt-subtitle font-bold text-xs uppercase tracking-widest text-accent'; |
| 53 | |
| 54 | // 4. Card BG |
| 55 | $card_style = $card_bg_color ? 'style="background-color: ' . esc_attr($card_bg_color) . ';"' : ''; |
| 56 | $card_class = $card_bg_color ? 'awt-card group rounded-xl shadow-sm hover:shadow-xl hover:-translate-y-1 transition duration-300 overflow-hidden border border-gray-100 flex flex-col h-full' : 'awt-card group bg-white rounded-xl shadow-sm hover:shadow-xl hover:-translate-y-1 transition duration-300 overflow-hidden border border-gray-100 flex flex-col h-full'; |
| 57 | |
| 58 | // 5. Book Title |
| 59 | $book_title_style = $title_color ? 'style="color: ' . esc_attr($title_color) . ';"' : ''; |
| 60 | $book_title_class = $title_color ? 'awt-book-title text-xl font-serif font-bold mb-1 transition' : 'awt-book-title text-xl font-serif font-bold text-primary mb-1 transition'; |
| 61 | |
| 62 | // 6. Author |
| 63 | $author_style = $author_color ? 'style="color: ' . esc_attr($author_color) . ';"' : ''; |
| 64 | $author_class = $author_color ? 'awt-author text-xs font-bold' : 'awt-author text-xs font-bold text-secondary'; |
| 65 | |
| 66 | // 7. Price |
| 67 | // Default price class is text-primary |
| 68 | $price_style = $price_color ? 'style="color: ' . esc_attr($price_color) . ';"' : ''; |
| 69 | $price_class = $price_color ? 'awt-price text-sm font-bold' : 'awt-price text-sm font-bold text-primary'; |
| 70 | |
| 71 | // 8. Buttons (View Details) |
| 72 | // Default: border-primary text-primary |
| 73 | $btn_outline_style = $accent_color ? 'style="border-color: ' . esc_attr($accent_color) . '; color: ' . esc_attr($accent_color) . ';"' : ''; |
| 74 | $btn_outline_class = $accent_color ? 'awt-btn awt-btn-outline flex-1 block py-2.5 border text-center text-xs font-bold uppercase rounded transition' : 'awt-btn awt-btn-outline flex-1 block py-2.5 border border-primary text-primary text-center text-xs font-bold uppercase rounded hover:bg-primary hover:text-white transition'; |
| 75 | |
| 76 | // 9. Arrows |
| 77 | $arrow_style = ''; |
| 78 | if ($arrow_bg_color || $arrow_icon_color) { |
| 79 | if ($arrow_bg_color) $arrow_style .= "background-color: {$arrow_bg_color};"; |
| 80 | if ($arrow_icon_color) $arrow_style .= "color: {$arrow_icon_color};"; |
| 81 | $arrow_style = 'style="' . esc_attr($arrow_style) . '"'; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | // Autoplay |
| 86 | $autoplay_bool = $enable_autoplay ? 'true' : 'false'; |
| 87 | |
| 88 | // Wrapper Attributes |
| 89 | $wrapper_attributes = get_block_wrapper_attributes([ |
| 90 | 'class' => $section_class, |
| 91 | 'style' => $section_bg_color ? "background-color: {$section_bg_color};" : '', |
| 92 | 'id' => 'other-books', |
| 93 | 'data-autoplay' => $autoplay_bool, |
| 94 | 'data-autoplay-speed' => $autoplay_speed, |
| 95 | 'data-columns' => $columns, |
| 96 | 'data-gap' => $gap |
| 97 | ]); |
| 98 | |
| 99 | // Query |
| 100 | $args = array( |
| 101 | 'post_type' => 'book', |
| 102 | 'posts_per_page' => $post_count, |
| 103 | 'post_status' => 'publish', |
| 104 | ); |
| 105 | $book_query = new WP_Query($args); |
| 106 | |
| 107 | if ($book_query->have_posts()) : |
| 108 | ?> |
| 109 | <section <?php echo $wrapper_attributes; ?>> |
| 110 | <div class="max-w-7xl mx-auto px-6 lg:px-8 relative"> |
| 111 | |
| 112 | <?php if ($show_section_title) : ?> |
| 113 | <div class="text-center mb-16"> |
| 114 | <!-- Library Label --> |
| 115 | <span class="<?php echo esc_attr($subtitle_class); ?>" <?php echo $subtitle_style; ?>> |
| 116 | <?php echo esc_html($section_subtitle); ?> |
| 117 | </span> |
| 118 | |
| 119 | <!-- Main Title --> |
| 120 | <h2 class="<?php echo esc_attr($title_class); ?>" <?php echo $title_style; ?>> |
| 121 | <?php echo esc_html($section_title); ?> |
| 122 | </h2> |
| 123 | </div> |
| 124 | <?php endif; ?> |
| 125 | |
| 126 | <div class="glide"> |
| 127 | <div class="glide__track" data-glide-el="track"> |
| 128 | <ul class="glide__slides py-8"> |
| 129 | <?php |
| 130 | while ($book_query->have_posts()) : $book_query->the_post(); |
| 131 | $book_id = get_the_ID(); |
| 132 | |
| 133 | // --- 1. Get Initial Prices from Meta --- |
| 134 | $raw_price = get_post_meta($book_id, '_rsbs_book_price', true); |
| 135 | $raw_sale_price = get_post_meta($book_id, '_rsbs_book_sale_price', true); |
| 136 | |
| 137 | // Clean data |
| 138 | $regular_price = (float) preg_replace('/[^0-9.]/', '', $raw_price); |
| 139 | $sale_price = (float) preg_replace('/[^0-9.]/', '', $raw_sale_price); |
| 140 | |
| 141 | // --- 2. Linked Product Override --- |
| 142 | if(function_exists('rswpbs_get_linked_product')){ |
| 143 | $linked_product = rswpbs_get_linked_product(); |
| 144 | if ($linked_product) { |
| 145 | $regular_price = $linked_product->get_regular_price(); |
| 146 | $sale_price = $linked_product->get_sale_price(); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // --- 3. Calculate Logic --- |
| 151 | $has_sale = !empty($sale_price) && $sale_price < $regular_price && $sale_price > 0; |
| 152 | $display_price = $has_sale ? $sale_price : $regular_price; |
| 153 | |
| 154 | $savings_pct = 0; |
| 155 | if ($has_sale && $regular_price > 0) { |
| 156 | $savings_pct = round((($regular_price - $sale_price) / $regular_price) * 100); |
| 157 | } |
| 158 | |
| 159 | // Other Data |
| 160 | $rating = get_post_meta($book_id, '_rsbs_average_book_rating', true); |
| 161 | if (!is_numeric($rating)) $rating = 0; |
| 162 | |
| 163 | $author_terms = get_the_terms($book_id, 'book-author'); |
| 164 | $author_name = $author_terms ? $author_terms[0]->name : 'Unknown Author'; |
| 165 | $cat_terms = get_the_terms($book_id, 'book-category'); |
| 166 | $cat_name = $cat_terms ? $cat_terms[0]->name : ''; |
| 167 | |
| 168 | $img_url = get_the_post_thumbnail_url($book_id, 'large'); |
| 169 | $short_desc = get_post_meta($book_id, '_rswpbs_short_description', true); |
| 170 | $permalink = get_permalink(); |
| 171 | $buy_links = get_post_meta($book_id, 'rswpbs_also_available_website_list', true); |
| 172 | $buy_btn_text = get_post_meta($book_id, '_rsbs_buy_btn_text', true); |
| 173 | $buy_btn_link = get_post_meta($book_id, '_rsbs_buy_btn_link', true); |
| 174 | $format_val = get_post_meta($book_id, '_rsbs_book_format', true); |
| 175 | |
| 176 | // Icons |
| 177 | $icon_star = '<svg class="w-3 h-3 text-yellow-400 fill-current" viewBox="0 0 20 20"><path d="M10 15l-5.878 3.09 1.123-6.545L.489 6.91l6.572-.955L10 0l2.939 5.955 6.572.955-4.756 4.635 1.123 6.545z"/></svg>'; |
| 178 | $icon_pen = '<svg class="w-3 h-3 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>'; |
| 179 | ?> |
| 180 | <li class="glide__slide h-auto"> |
| 181 | <div class="<?php echo esc_attr($card_class); ?>" <?php echo $card_style; ?>> |
| 182 | <div class="relative p-6 bg-[#f1f5f9] flex justify-center items-center h-64 overflow-hidden"> |
| 183 | <?php if($format_val): ?> |
| 184 | <span class="absolute top-4 left-4 bg-accent text-white text-[10px] font-bold px-2 py-1 rounded uppercase z-10" <?php echo $accent_color ? 'style="background-color: '.esc_attr($accent_color).';"' : ''; ?>> |
| 185 | <?php echo esc_html($format_val); ?> |
| 186 | </span> |
| 187 | <?php endif; ?> |
| 188 | |
| 189 | <?php if($img_url): ?> |
| 190 | <img src="<?php echo esc_url($img_url); ?>" class="h-48 shadow-lg rounded transform group-hover:scale-105 transition duration-500"> |
| 191 | <?php else: ?> |
| 192 | <div class="h-48 w-32 bg-gray-200 shadow-lg rounded flex items-center justify-center text-gray-400 text-xs">No Image</div> |
| 193 | <?php endif; ?> |
| 194 | </div> |
| 195 | |
| 196 | <div class="p-5 flex-1 flex flex-col"> |
| 197 | |
| 198 | <div class="mb-3 flex justify-between items-start"> |
| 199 | <span class="text-[10px] font-bold text-accent uppercase tracking-widest px-1 py-0.5 rounded mt-1" <?php echo $accent_color ? 'style="color: '.esc_attr($accent_color).';"' : ''; ?>> |
| 200 | <?php echo esc_html($cat_name); ?> |
| 201 | </span> |
| 202 | |
| 203 | <div class="flex flex-col items-end"> |
| 204 | <?php if ($has_sale) : ?> |
| 205 | <span class="text-[10px] font-bold text-emerald-600 bg-emerald-50 px-1.5 py-0.5 rounded mb-1"> |
| 206 | Save <?php echo $savings_pct; ?>% |
| 207 | </span> |
| 208 | <div class="flex items-center gap-1.5 leading-none"> |
| 209 | <span class="text-xs text-gray-400 line-through decoration-gray-400"> |
| 210 | $<?php echo number_format($regular_price, 2); ?> |
| 211 | </span> |
| 212 | <span class="<?php echo esc_attr($price_class); ?>" <?php echo $price_style; ?>> |
| 213 | $<?php echo number_format($sale_price, 2); ?> |
| 214 | </span> |
| 215 | </div> |
| 216 | <?php else : ?> |
| 217 | <span class="<?php echo esc_attr($price_class); ?> mt-1" <?php echo $price_style; ?>> |
| 218 | <?php echo $display_price > 0 ? '$' . number_format($display_price, 2) : 'Free'; ?> |
| 219 | </span> |
| 220 | <?php endif; ?> |
| 221 | </div> |
| 222 | </div> |
| 223 | |
| 224 | <h3 class="<?php echo esc_attr($book_title_class); ?>"> |
| 225 | <a href="<?php echo esc_url($permalink); ?>" <?php echo $book_title_style; ?>><?php |
| 226 | echo $enable_title_trim ? wp_trim_words(get_the_title(), $title_trim_length) : get_the_title(); |
| 227 | ?></a> |
| 228 | </h3> |
| 229 | |
| 230 | <div class="flex items-center mb-2"> |
| 231 | <div class="flex text-yellow-400 text-xs gap-0.5"> |
| 232 | <?php for($i=1; $i<=5; $i++) { |
| 233 | echo $i <= $rating ? $icon_star : str_replace('text-yellow-400', 'text-gray-300', $icon_star); |
| 234 | } ?> |
| 235 | </div> |
| 236 | <span class="text-[10px] text-gray-400 font-medium ml-1.5">(<?php echo esc_html($rating); ?>)</span> |
| 237 | </div> |
| 238 | |
| 239 | <div class="flex items-center gap-2 mb-3"> |
| 240 | <?php echo $icon_pen; ?> |
| 241 | <span class="<?php echo esc_attr($author_class); ?>" <?php echo $author_style; ?>><?php echo esc_html($author_name); ?></span> |
| 242 | </div> |
| 243 | |
| 244 | <p class="text-xs text-secondary mb-4 line-clamp-3 leading-relaxed"><?php echo esc_html(wp_trim_words($short_desc, 20)); ?></p> |
| 245 | |
| 246 | <div class="mt-auto space-y-3"> |
| 247 | <div class="flex flex-wrap gap-2"> |
| 248 | <?php |
| 249 | echo '<a target="_blank" href="'.esc_url($buy_btn_link).'" |
| 250 | class="flex-1 min-w-[110px] flex items-center justify-center gap-1 py-2 bg-gray-50 border border-gray-200 rounded text-xs font-bold text-primary hover:bg-white hover:border-[#FF9900] hover:text-[#FF9900] transition">' |
| 251 | . esc_html($buy_btn_text) . |
| 252 | '</a>'; |
| 253 | |
| 254 | if (!empty($buy_links)) { |
| 255 | foreach (array_slice($buy_links, 0, 4) as $link) { |
| 256 | echo '<a target="_blank" href="'.esc_url($link['book_url']).'" |
| 257 | class="flex-1 min-w-[110px] flex items-center justify-center gap-1 py-2 bg-gray-50 border border-gray-200 rounded text-xs font-bold text-primary hover:bg-white hover:border-[#FF9900] hover:text-[#FF9900] transition">' |
| 258 | . esc_html($link['website_name']) . |
| 259 | '</a>'; |
| 260 | } |
| 261 | } |
| 262 | ?> |
| 263 | </div> |
| 264 | |
| 265 | <div class="flex items-center gap-2 w-full"> |
| 266 | |
| 267 | <?php |
| 268 | // 1. Shortcode Check & Output |
| 269 | if ( shortcode_exists('rswpbs_book_loop_btn') ) { |
| 270 | echo do_shortcode( '[rswpbs_book_loop_btn]' ); |
| 271 | } |
| 272 | ?> |
| 273 | |
| 274 | <a href="<?php echo esc_url($permalink); ?>" class="<?php echo esc_attr($btn_outline_class); ?>" <?php echo $btn_outline_style; ?>> |
| 275 | <?php _e('View Details', 'author-website-templates'); ?> |
| 276 | </a> |
| 277 | </div> |
| 278 | |
| 279 | </div> |
| 280 | </div> |
| 281 | </div> |
| 282 | </li> |
| 283 | <?php endwhile; wp_reset_postdata(); ?> |
| 284 | </ul> |
| 285 | </div> |
| 286 | |
| 287 | <!-- Arrows --> |
| 288 | <div class="glide__arrows" data-glide-el="controls"> |
| 289 | <button class="awt-arrow glide__arrow glide__arrow--left" data-glide-dir="<" <?php echo $arrow_style; ?>> |
| 290 | <svg class="w-6 h-6" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"> |
| 291 | <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" /> |
| 292 | </svg> |
| 293 | </button> |
| 294 | <button class="awt-arrow glide__arrow glide__arrow--right" data-glide-dir=">" <?php echo $arrow_style; ?>> |
| 295 | <svg class="w-6 h-6" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"> |
| 296 | <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" /> |
| 297 | </svg> |
| 298 | </button> |
| 299 | </div> |
| 300 | </div> |
| 301 | |
| 302 | <?php if ($show_view_all) : ?> |
| 303 | <div class="mt-16 text-center"> |
| 304 | <a href="<?php echo esc_url($view_all_link); ?>" |
| 305 | class="awt-btn-view-all inline-flex items-center gap-2 px-8 py-3 border font-bold text-sm uppercase tracking-wider rounded-full transition duration-300 group" |
| 306 | <?php echo $title_color ? 'style="color: ' . esc_attr($title_color) . '; border-color: ' . esc_attr($title_color) . ';"' : 'style="border-color: currentColor;"'; ?>> |
| 307 | <?php echo esc_html($view_all_text); ?> <i class="fas fa-arrow-right group-hover:translate-x-1 transition-transform"></i> |
| 308 | </a> |
| 309 | </div> |
| 310 | <?php endif; ?> |
| 311 | |
| 312 | </div> |
| 313 | </section> |
| 314 | <?php |
| 315 | else : |
| 316 | ?> |
| 317 | <p><?php esc_html_e('No books found.', 'author-website-templates'); ?></p> |
| 318 | <?php |
| 319 | endif; |