content-front-page-panels.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Template part for displaying pages on front page
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Seventeen
  7. * @since 1.0
  8. * @version 1.0
  9. */
  10. global $twentyseventeencounter;
  11. ?>
  12. <article id="panel<?php echo $twentyseventeencounter; ?>" <?php post_class( 'twentyseventeen-panel ' ); ?> >
  13. <?php
  14. if ( has_post_thumbnail() ) :
  15. $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'twentyseventeen-featured-image' );
  16. // Calculate aspect ratio: h / w * 100%.
  17. $ratio = $thumbnail[2] / $thumbnail[1] * 100;
  18. ?>
  19. <div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);">
  20. <div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div>
  21. </div><!-- .panel-image -->
  22. <?php endif; ?>
  23. <div class="panel-content">
  24. <div class="wrap">
  25. <header class="entry-header">
  26. <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
  27. <?php twentyseventeen_edit_link( get_the_ID() ); ?>
  28. </header><!-- .entry-header -->
  29. <div class="entry-content">
  30. <?php
  31. the_content(
  32. sprintf(
  33. /* translators: %s: Post title. */
  34. __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
  35. get_the_title()
  36. )
  37. );
  38. ?>
  39. </div><!-- .entry-content -->
  40. <?php
  41. // Show recent blog posts if is blog posts page (Note that get_option returns a string, so we're casting the result as an int).
  42. if ( get_the_ID() === (int) get_option( 'page_for_posts' ) ) :
  43. ?>
  44. <?php
  45. // Show three most recent posts.
  46. $recent_posts = new WP_Query(
  47. array(
  48. 'posts_per_page' => 3,
  49. 'post_status' => 'publish',
  50. 'ignore_sticky_posts' => true,
  51. 'no_found_rows' => true,
  52. )
  53. );
  54. ?>
  55. <?php if ( $recent_posts->have_posts() ) : ?>
  56. <div class="recent-posts">
  57. <?php
  58. while ( $recent_posts->have_posts() ) :
  59. $recent_posts->the_post();
  60. get_template_part( 'template-parts/post/content', 'excerpt' );
  61. endwhile;
  62. wp_reset_postdata();
  63. ?>
  64. </div><!-- .recent-posts -->
  65. <?php endif; ?>
  66. <?php endif; ?>
  67. </div><!-- .wrap -->
  68. </div><!-- .panel-content -->
  69. </article><!-- #post-<?php the_ID(); ?> -->