1
0

content-thumb.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. //add_filter( 'excerpt_length', 'custom_excerpt_length', 120 );
  61. ?>
  62. <article class="post post-list-thumb <?php echo $class; ?>" itemscope="" itemtype="http://schema.org/BlogPosting">
  63. <div class="post-thumb">
  64. <a href="<?php the_permalink(); ?>">
  65. <?php echo $cover_html; ?>
  66. </a>
  67. </div><!-- thumbnail-->
  68. <div class="post-content-wrap">
  69. <div class="post-content">
  70. <div class="post-date">
  71. <i class="iconfont icon-time"></i><?php echo poi_time_since(strtotime($post->post_date)); ?>
  72. <?php if (is_sticky()) : ?>
  73. &nbsp;<i class="iconfont hotpost icon-hot"></i>
  74. <?php endif ?>
  75. </div>
  76. <a href="<?php the_permalink(); ?>" class="post-title">
  77. <h3><?php the_title(); ?></h3>
  78. </a>
  79. <div class="post-meta">
  80. <?php
  81. if (iro_opt("is_author_meta_show")) {
  82. if (!function_exists('get_author_meta_spans')) {
  83. require get_stylesheet_directory() . '/tpl/meta-author.php';
  84. }
  85. get_author_meta_spans();
  86. }
  87. ?>
  88. <span><i class="iconfont icon-attention"></i><?php echo get_post_views(get_the_ID()) . ' ' . _n('Hit', 'Hits', get_post_views(get_the_ID()), 'sakurairo')/*热度*/ ?></span>
  89. <span class="comments-number">
  90. <i class="iconfont icon-mark"></i>
  91. <?php comments_popup_link(__("NOTHING", "sakurairo"), __("1 Comment", "sakurairo")/*条评论*/, '% ' . __("Comments", "sakurairo")/*条评论*/, '', __("Comment Closed", "sakurairo")
  92. /**评论关闭 */
  93. ); ?>
  94. </span>
  95. <span><i class="iconfont icon-file"></i>
  96. <a href="<?php
  97. if (isset($the_cat[0])) {
  98. echo $cat_id = esc_url(get_category_link($the_cat[0]->cat_ID ?? ''));
  99. }
  100. ?>">
  101. <?php
  102. if (isset($the_cat[0])) {
  103. echo $the_cat[0]->cat_name ?? '未分类';
  104. } else {
  105. echo '未分类';
  106. }
  107. ?>
  108. </a>
  109. </span>
  110. </div>
  111. <div class="float-content">
  112. <?php the_excerpt() ?>
  113. <div class="post-bottom">
  114. <a href="<?php the_permalink(); ?>" class="button-normal"><i class="iconfont icon-caidan"></i></a>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </article>
  120. <?php
  121. endwhile;