1
0

content-thumb.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Template part for displaying posts.
  4. *
  5. * @link https://codex.wordpress.org/Template_Hierarchy
  6. *
  7. * @package Akina
  8. */
  9. //function custom_short_excerpt($excerpt){
  10. // return substr($excerpt, 0, 120);
  11. //}
  12. //add_filter('the_excerpt', 'custom_short_excerpt');
  13. $i = 0;
  14. while (have_posts()) : the_post();
  15. $i++;
  16. if ($i == 1) {
  17. $class = ' post-list-show';
  18. }
  19. //封面视频
  20. //@seealso https://github.com/mashirozx/Sakura/wiki/%E6%96%87%E7%AB%A0%E5%B0%81%E9%9D%A2%E8%A7%86%E9%A2%91
  21. $use_as_thumb = get_post_meta(get_the_ID(), 'use_as_thumb', true); //'true','only',(default)
  22. $cover_type = ($use_as_thumb == 'true' || $use_as_thumb == 'only') ? get_post_meta(get_the_ID(), 'cover_type', true) : '';
  23. $cover_html = "";
  24. switch ($cover_type) {
  25. case 'hls':
  26. $video_cover = get_post_meta(get_the_ID(), 'video_cover', true);
  27. $cover_html = '<video class="hls" poster="' . iro_opt('load_out_svg') . '#lazyload-blur" src="' . $video_cover . '" loop muted="true" disablePictureInPicture disableRemotePlayback playsinline>'
  28. . __('Your browser does not support HTML5 video.', 'sakurairo')
  29. . '</video>';
  30. break;
  31. case 'normal':
  32. $video_cover = get_post_meta(get_the_ID(), 'video_cover', true);
  33. $cover_html = '<video class="lazyload" poster="' . iro_opt('load_out_svg') . '#lazyload-blur" data-src="' . $video_cover . '" autoplay loop muted="true" disablePictureInPicture disableRemotePlayback playsinline>'
  34. . __('Your browser does not support HTML5 video.', 'sakurairo')
  35. . '</video>';
  36. break;
  37. default:
  38. $post_img = '';
  39. if (has_post_thumbnail()) {
  40. $post_thumbnail_id = get_post_thumbnail_id($post->ID);
  41. $large_image_url = wp_get_attachment_image_src($post_thumbnail_id, 'large');
  42. if ($large_image_url == false) {
  43. $large_image_url = wp_get_attachment_image_src($post_thumbnail_id, 'medium');
  44. if ($large_image_url == false) {
  45. $large_image_url = wp_get_attachment_image_src($post_thumbnail_id);
  46. if ($large_image_url == false) {
  47. $post_img = DEFAULT_FEATURE_IMAGE();
  48. }
  49. }
  50. }
  51. $post_img = $large_image_url[0] ?? DEFAULT_FEATURE_IMAGE('th');
  52. } else {
  53. $post_img = DEFAULT_FEATURE_IMAGE('th');
  54. }
  55. $cover_html = '<img class="lazyload" src="' . iro_opt('load_out_svg') . '#lazyload-blur" data-src="' . $post_img . '"/>';
  56. break;
  57. }
  58. $the_cat = get_the_category();
  59. // 摘要字数限制
  60. $ai_excerpt = get_post_meta($post->ID, POST_METADATA_KEY, true);
  61. $excerpt = has_excerpt();
  62. //add_filter( 'excerpt_length', 'custom_excerpt_length', 120 );
  63. ?>
  64. <article class="post post-list-thumb <?php echo $class; ?>" itemscope="" itemtype="http://schema.org/BlogPosting">
  65. <div class="post-thumb">
  66. <a href="<?php the_permalink(); ?>">
  67. <?php echo $cover_html; ?>
  68. </a>
  69. </div><!-- thumbnail-->
  70. <div class="post-content-wrap">
  71. <div class="post-content">
  72. <div class="post-date">
  73. <i class="fa-regular fa-clock"></i><?php echo poi_time_since(strtotime($post->post_date)); ?>
  74. <?php if (is_sticky()) : ?>
  75. &nbsp;<i class="fa-regular fa-gem"></i>
  76. <?php endif ?>
  77. </div>
  78. <a href="<?php the_permalink(); ?>" class="post-title">
  79. <h3><?php the_title(); ?></h3>
  80. </a>
  81. <div class="post-meta">
  82. <?php
  83. if (iro_opt("is_author_meta_show")) {
  84. if (!function_exists('get_author_meta_spans')) {
  85. require get_stylesheet_directory() . '/tpl/meta-author.php';
  86. }
  87. get_author_meta_spans();
  88. }
  89. ?>
  90. <span><i class="fa-regular fa-eye"></i><?php echo get_post_views(get_the_ID()) . ' ' . _n('Hit', 'Hits', get_post_views(get_the_ID()), 'sakurairo')/*热度*/ ?></span>
  91. <span class="comments-number">
  92. <i class="fa-regular fa-comment"></i>
  93. <?php comments_popup_link(__("NOTHING", "sakurairo"), __("1 Comment", "sakurairo")/*条评论*/, '% ' . __("Comments", "sakurairo")/*条评论*/, '', __("Comment Closed", "sakurairo")
  94. /**评论关闭 */
  95. ); ?>
  96. </span>
  97. <span><i class="fa-regular fa-folder"></i>
  98. <a href="<?php
  99. if (isset($the_cat[0])) {
  100. echo $cat_id = esc_url(get_category_link($the_cat[0]->cat_ID ?? ''));
  101. }
  102. ?>">
  103. <?php
  104. if (isset($the_cat[0])) {
  105. echo $the_cat[0]->cat_name ?? '未分类';
  106. } else {
  107. echo '未分类';
  108. }
  109. ?>
  110. </a>
  111. </span>
  112. </div>
  113. <div class="float-content">
  114. <?php if(!empty($ai_excerpt) && empty($excerpt)) { ?>
  115. <div class="ai-excerpt-tip"><i class="fa-regular fa-lightbulb"></i><?php _e("AI Excerpt", "sakurairo") ?></div>
  116. <?php } ?>
  117. <?php the_excerpt() ?>
  118. </div>
  119. </div>
  120. </div>
  121. </article>
  122. <?php
  123. endwhile;