content-front-page-panels.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Template part for displaying pages on front page.
  4. *
  5. * @package Lodestar
  6. */
  7. global $lodestarcounter;
  8. $current_panel_layout = 'lodestar_panel' . $lodestarcounter . '_layout';
  9. $panel_layout = get_theme_mod( $current_panel_layout, 'one-column' );
  10. ?>
  11. <article id="post-<?php the_ID(); ?>" <?php post_class( 'lodestar-panel ' . esc_attr( $panel_layout ) ); ?> >
  12. <span class="panel lodestar-panel<?php echo esc_attr( $lodestarcounter ); ?>" id="panel<?php echo esc_attr( $lodestarcounter ); ?>">
  13. <span class="lodestar-panel-title"><?php printf( esc_html__( 'Panel %1$s', 'lodestar' ), esc_attr( $lodestarcounter ) ); ?></span>
  14. </span>
  15. <?php if ( has_post_thumbnail() ) :
  16. $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'lodestar-featured-image' );
  17. $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
  18. $thumbnail_attributes = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'lodestar-featured-image' );
  19. //Calculate aspect ratio: h / w * 100%
  20. $ratio = $thumbnail_attributes[2] / $thumbnail_attributes[1] * 100;
  21. ?>
  22. <div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);">
  23. <div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div>
  24. </div>
  25. <?php endif; ?>
  26. <div class="panel-content">
  27. <div class="wrap">
  28. <header class="entry-header">
  29. <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
  30. <?php lodestar_edit_link( get_the_ID() ); ?>
  31. </header><!-- .entry-header -->
  32. <div class="entry-content">
  33. <?php
  34. /* translators: %s: Name of current post */
  35. the_content( sprintf(
  36. wp_kses( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'lodestar' ), array( 'span' => array( 'class' => array() ) ) ),
  37. the_title( '<span class="screen-reader-text">"', '"</span>', false )
  38. ) );
  39. ?>
  40. </div><!-- .entry-content -->
  41. <?php
  42. // Show portfolio projects
  43. if ( 'templates/portfolio-page.php' === get_page_template_slug() ) :
  44. // show 6 latest portfolio projects
  45. $args = array(
  46. 'post_type' => 'jetpack-portfolio',
  47. 'posts_per_page' => 6,
  48. 'no_found_rows' => true,
  49. );
  50. $project_query = new WP_Query ( $args );
  51. ?>
  52. <?php if ( post_type_exists( 'jetpack-portfolio' ) && $project_query -> have_posts() ) : ?>
  53. <div class="portfolio-projects">
  54. <?php
  55. while ( $project_query -> have_posts() ) : $project_query -> the_post();
  56. get_template_part( 'components/features/portfolio/content', 'portfolio' );
  57. endwhile;
  58. ?>
  59. </div><!-- .portfolio-projects -->
  60. <?php endif; ?>
  61. <?php wp_reset_postdata(); ?>
  62. <?php
  63. // Show testimpnials
  64. elseif ( 'templates/testimonial-page.php' === get_page_template_slug() ) : ?>
  65. <?php
  66. // Show two random testimonials
  67. $args = array(
  68. 'orderby' => 'rand',
  69. 'post_type' => 'jetpack-testimonial',
  70. 'posts_per_page' => 2,
  71. 'no_found_rows' => true,
  72. );
  73. $testimonial_query = new WP_Query ( $args );
  74. ?>
  75. <?php if ( post_type_exists( 'jetpack-testimonial' ) && $testimonial_query -> have_posts() ) : ?>
  76. <div class="testimonials">
  77. <?php
  78. while ( $testimonial_query -> have_posts() ) : $testimonial_query -> the_post();
  79. get_template_part( 'components/features/testimonials/content', 'testimonials' );
  80. endwhile;
  81. ?>
  82. </div><!-- .testimonials -->
  83. <?php endif; ?>
  84. <?php wp_reset_postdata(); ?>
  85. <?php
  86. // Show recent blog posts
  87. // (Note that get_option returns a string, so we're casting the result as an int).
  88. elseif ( get_the_ID() === (int) get_option( 'page_for_posts' ) ) : ?>
  89. <?php // Show four most recent posts.
  90. $args = array(
  91. 'posts_per_page' => 2,
  92. 'post_status' => 'publish',
  93. 'ignore_sticky_posts' => true,
  94. 'no_found_rows' => true,
  95. );
  96. $recent_posts = new WP_Query ( $args );
  97. ?>
  98. <?php if ( $recent_posts->have_posts() ) : ?>
  99. <div class="recent-posts">
  100. <?php
  101. while ( $recent_posts->have_posts() ) : $recent_posts->the_post();
  102. get_template_part( 'components/post/content', 'excerpt' );
  103. endwhile;
  104. ?>
  105. </div><!-- .recent-posts -->
  106. <?php endif; ?>
  107. <?php wp_reset_postdata(); ?>
  108. <?php endif; ?>
  109. </div><!-- .wrap -->
  110. </div><!-- .panel-content -->
  111. </article><!-- #post-## -->