content-front-page-panels.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 if ( has_post_thumbnail() ) :
  14. $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'twentyseventeen-featured-image' );
  15. // Calculate aspect ratio: h / w * 100%.
  16. $ratio = $thumbnail[2] / $thumbnail[1] * 100;
  17. ?>
  18. <div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);">
  19. <div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div>
  20. </div><!-- .panel-image -->
  21. <?php endif; ?>
  22. <div class="panel-content">
  23. <div class="wrap">
  24. <header class="entry-header">
  25. <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
  26. <?php twentyseventeen_edit_link( get_the_ID() ); ?>
  27. </header><!-- .entry-header -->
  28. <div class="entry-content">
  29. <?php
  30. /* translators: %s: Name of current post */
  31. the_content( sprintf(
  32. __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ),
  33. get_the_title()
  34. ) );
  35. ?>
  36. </div><!-- .entry-content -->
  37. <?php
  38. // 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).
  39. if ( get_the_ID() === (int) get_option( 'page_for_posts' ) ) : ?>
  40. <?php // Show four most recent posts.
  41. $recent_posts = new WP_Query( array(
  42. 'posts_per_page' => 3,
  43. 'post_status' => 'publish',
  44. 'ignore_sticky_posts' => true,
  45. 'no_found_rows' => true,
  46. ) );
  47. ?>
  48. <?php if ( $recent_posts->have_posts() ) : ?>
  49. <div class="recent-posts">
  50. <?php
  51. while ( $recent_posts->have_posts() ) : $recent_posts->the_post();
  52. get_template_part( 'template-parts/post/content', 'excerpt' );
  53. endwhile;
  54. wp_reset_postdata();
  55. ?>
  56. </div><!-- .recent-posts -->
  57. <?php endif; ?>
  58. <?php endif; ?>
  59. </div><!-- .wrap -->
  60. </div><!-- .panel-content -->
  61. </article><!-- #post-## -->