content-thumb.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Template part for displaying posts and shuoshuo.
  4. *
  5. * @link https://codex.wordpress.org/Template_Hierarchy
  6. *
  7. * @package Sakurairo
  8. */
  9. // Combine posts and shuoshuo
  10. $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  11. // Determine if we are on an author page
  12. $is_author_page = is_author() && !is_home() && !is_category() && !is_tag();
  13. $sticky_posts = get_option('sticky_posts');
  14. // Query for sticky posts (only on the first page)
  15. if ($paged == 1 && !empty($sticky_posts)) {
  16. $sticky_args = array(
  17. 'post_type' => array('post', 'shuoshuo'),
  18. 'post_status' => 'publish',
  19. 'posts_per_page' => -1, // Get all sticky posts
  20. 'post__in' => $sticky_posts,
  21. 'orderby' => 'post_date',
  22. 'order' => 'DESC',
  23. );
  24. if ($is_author_page) {
  25. $sticky_args['author'] = get_the_author_meta('ID');
  26. }
  27. $sticky_query = new WP_Query($sticky_args);
  28. // Display sticky posts
  29. if ($sticky_query->have_posts()) :
  30. while ($sticky_query->have_posts()) : $sticky_query->the_post();
  31. get_template_part('tpl/content', 'thumbcard');
  32. endwhile;
  33. endif;
  34. }
  35. // Query for non-sticky posts
  36. $non_sticky_args = array(
  37. 'post_type' => array('post', 'shuoshuo'),
  38. 'post_status' => 'publish',
  39. 'posts_per_page' => 10, // 每页显示10篇文章
  40. 'orderby' => 'post_date',
  41. 'order' => 'DESC',
  42. 'paged' => $paged,
  43. 'post__not_in' => $sticky_posts,
  44. 'ignore_sticky_posts' => 1
  45. );
  46. if ($is_author_page) {
  47. $non_sticky_args['author'] = get_the_author_meta('ID'); // 只获取当前作者的文章
  48. }
  49. $non_sticky_query = new WP_Query($non_sticky_args);
  50. // Display non-sticky posts
  51. if ($non_sticky_query->have_posts()) :
  52. while ($non_sticky_query->have_posts()) : $non_sticky_query->the_post();
  53. get_template_part('tpl/content', 'thumbcard');
  54. endwhile;
  55. endif;
  56. ?>