1
0

content-thumbcard.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. if (!function_exists('render_meta_views')) {
  3. function render_meta_views() {
  4. ?><span><i class="fa-regular fa-eye"></i><?= esc_html(get_post_views(get_the_ID()) . ' ' . _n('Hit', 'Hits', get_post_views(get_the_ID()), 'sakurairo'))/*热度*/ ?></span><?php
  5. }
  6. }
  7. // @related inc/post-metadata.php
  8. if (!function_exists('render_article_meta')) {
  9. function render_article_meta() {
  10. $article_meta_display_options = iro_opt("article_meta_displays", array("post_views", "comment_count", "category"));
  11. foreach ($article_meta_display_options as $key) {
  12. switch ($key) {
  13. case "author":
  14. require_once get_stylesheet_directory() . '/tpl/meta-author.php';
  15. render_author_meta();
  16. break;
  17. case "category":
  18. require_once get_stylesheet_directory() . '/tpl/meta-category.php';
  19. echo get_meta_category_html();
  20. break;
  21. case "comment_count":
  22. require_once get_stylesheet_directory() . '/tpl/meta-comments.php';
  23. render_meta_comments();
  24. break;
  25. case "post_views":
  26. render_meta_views();
  27. break;
  28. case "post_words_count":
  29. require_once get_stylesheet_directory() . '/tpl/meta-words-count.php';
  30. $str = get_meta_words_count();
  31. if ($str) {
  32. ?><span><i class="fa-regular fa-pen-to-square"></i><?= esc_html($str) ?></span><?php
  33. }
  34. break;
  35. case "reading_time":
  36. require_once get_stylesheet_directory() . '/tpl/meta-ert.php';
  37. $str = get_meta_estimate_reading_time();
  38. if ($str) {
  39. ?><span title="<?= esc_attr(__("Estimate Reading Time", "sakurairo")) ?>"><i class="fa-solid fa-hourglass"></i><?= esc_html($str) ?></span><?php
  40. }
  41. default:
  42. }
  43. }
  44. }
  45. }
  46. if (!function_exists('get_post_cover_html')) {
  47. function get_post_cover_html() {
  48. global $post;
  49. $use_as_thumb = get_post_meta(get_the_ID(), 'use_as_thumb', true); //'true','only',(default)
  50. $cover_type = ($use_as_thumb == 'true' || $use_as_thumb == 'only') ? get_post_meta(get_the_ID(), 'cover_type', true) : '';
  51. $cover_html = "";
  52. switch ($cover_type) {
  53. case 'hls':
  54. $video_cover = get_post_meta(get_the_ID(), 'video_cover', true);
  55. $cover_html = '<video class="hls" poster="' . esc_url(iro_opt('load_out_svg')) . '#lazyload-blur" src="' . esc_url($video_cover) . '" loop muted="true" disablePictureInPicture disableRemotePlayback playsinline>'
  56. . __('Your browser does not support HTML5 video.', 'sakurairo')
  57. . '</video>';
  58. break;
  59. case 'normal':
  60. $video_cover = get_post_meta(get_the_ID(), 'video_cover', true);
  61. $cover_html = '<video class="lazyload" poster="' . esc_url(iro_opt('load_out_svg')) . '#lazyload-blur" data-src="' . esc_url($video_cover) . '" autoplay loop muted="true" disablePictureInPicture disableRemotePlayback playsinline>'
  62. . __('Your browser does not support HTML5 video.', 'sakurairo')
  63. . '</video>';
  64. break;
  65. default:
  66. $post_img = '';
  67. if (has_post_thumbnail()) {
  68. $post_thumbnail_id = get_post_thumbnail_id($post->ID);
  69. $large_image_url = wp_get_attachment_image_src($post_thumbnail_id, 'large');
  70. if ($large_image_url == false) {
  71. $large_image_url = wp_get_attachment_image_src($post_thumbnail_id, 'medium');
  72. if ($large_image_url == false) {
  73. $large_image_url = wp_get_attachment_image_src($post_thumbnail_id);
  74. if ($large_image_url == false) {
  75. $post_img = DEFAULT_FEATURE_IMAGE();
  76. }
  77. }
  78. }
  79. $post_img = $large_image_url[0] ?? DEFAULT_FEATURE_IMAGE('th');
  80. } else {
  81. $post_img = DEFAULT_FEATURE_IMAGE('th');
  82. }
  83. $cover_html = '<img alt="post_img" class="lazyload" src="' . esc_url(iro_opt('load_out_svg')) . '#lazyload-blur" data-src="' . esc_url($post_img) . '"/>';
  84. break;
  85. }
  86. return $cover_html;
  87. }
  88. }
  89. // Determine post type
  90. $post_type = get_post_type();
  91. if ($post_type == 'shuoshuo') {
  92. // shuoshuo 样式
  93. $cover_html = get_post_cover_html();
  94. $emotion = get_post_meta(get_the_ID(), 'emotion', true);
  95. if (empty($emotion)) {
  96. $emotion = '\f86d'; // 默认值
  97. }
  98. $emotion_color = get_post_meta(get_the_ID(), 'emotion_color', true);
  99. if (empty($emotion_color)) {
  100. $emotion_color = iro_opt('theme_skin_matching');
  101. }
  102. $unique_id = 'shuoshuo-' . get_the_ID();
  103. ?>
  104. <article class="shuoshuo-item" id="<?php echo esc_attr($unique_id); ?>">
  105. <div class="shuoshuo-content-wrapper">
  106. <div class="shuoshuo-avatar">
  107. <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>">
  108. <img src="<?php echo esc_url(get_avatar_profile_url(get_the_author_meta('ID'))); ?>" class="avatar avatar-48" width="48" height="48">
  109. </a>
  110. <style>
  111. #<?php echo esc_attr($unique_id); ?> .shuoshuo-avatar::after {
  112. content: "<?php echo esc_attr($emotion); ?>";
  113. font-family:'FontAwesome';
  114. position: absolute;
  115. bottom: 0;
  116. right: -3px;
  117. background-color: <?php echo esc_attr($emotion_color); ?>;
  118. color: #fff;
  119. padding: 3px 6px;
  120. border-radius: 30px;
  121. font-size: 12px;
  122. }
  123. </style>
  124. </div>
  125. <div class="shuoshuo-wrapper">
  126. <div class="shuoshuo-meta">
  127. <span class="shuoshuo-author-name">
  128. <a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>">
  129. <?php the_author(); ?>
  130. </a>
  131. </span>
  132. <span class="shuoshuo-title"><h3><?php the_title(); ?> </h3></span>
  133. <div class="shuoshuo-info">
  134. <?php if (get_comments_number() > 0) : ?>
  135. <span class="shuoshuo-comments"><i class="fa-regular fa-comment"></i> <?php comments_number('0', '1', '%'); ?> </span>
  136. <?php endif; ?>
  137. <span class="shuoshuo-date"><i class="fa-regular fa-clock"> </i> <?php the_time('Y-m-d H:i'); ?> </span>
  138. </div>
  139. </div>
  140. <a href="<?php the_permalink(); ?>" class="shuoshuo-content-link">
  141. <div class="shuoshuo-content">
  142. <?php the_content(); ?>
  143. </div>
  144. </a>
  145. </div>
  146. </div>
  147. </article>
  148. <?php
  149. } else {
  150. // 原文章样式
  151. $cover_html = get_post_cover_html();
  152. // 摘要字数限制
  153. $ai_excerpt = get_post_meta($post->ID, POST_METADATA_KEY, true);
  154. $excerpt = has_excerpt();
  155. ?>
  156. <article class="post post-list-thumb" itemscope="" itemtype="http://schema.org/BlogPosting">
  157. <div class="post-thumb">
  158. <a href="<?php the_permalink(); ?>">
  159. <?php echo $cover_html; ?>
  160. </a>
  161. </div><!-- thumbnail-->
  162. <div class="post-date">
  163. <i class="fa-regular fa-clock"></i><?= esc_html(poi_time_since(strtotime($post->post_date))) ?>
  164. <?php if (is_sticky()) : ?>
  165. &nbsp;<div class="post-top"><i class="fa-solid fa-chess-queen"></i><?php _e("Sticky", "sakurairo") ?></div>
  166. <?php endif ?>
  167. </div>
  168. <div class="post-meta">
  169. <?php render_article_meta() ?>
  170. </div>
  171. <?php $title_style = get_post_meta(get_the_ID(), 'title_style', true); ?>
  172. <div class="post-title" style="<?php echo esc_attr($title_style); ?>">
  173. <a href="<?php the_permalink(); ?>">
  174. <h3><?php the_title(); ?></h3>
  175. </a>
  176. </div>
  177. <div class="post-excerpt">
  178. <?php if (!empty($ai_excerpt) && empty($excerpt)) { ?>
  179. <div class="ai-excerpt-tip"><i class="fa-solid fa-atom"></i><?php _e("AI Excerpt", "sakurairo") ?></div>
  180. <?php } ?>
  181. <?php if (empty($ai_excerpt)) { ?>
  182. <div class="ai-excerpt-tip"><i class="fa-solid fa-bars-staggered"></i><?php _e("Excerpt", "sakurairo") ?></div>
  183. <?php } ?>
  184. <?php the_excerpt() ?>
  185. </div>
  186. </article>
  187. <?php
  188. }