content-front-page-panels.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 = 100;
  21. if ( isset($thumbnail_attributes[2] ) && isset( $thumbnail_attributes[1] ) && $thumbnail_attributes[1] > 0 ) {
  22. $ratio = $thumbnail_attributes[2] / $thumbnail_attributes[1] * 100;
  23. }
  24. ?>
  25. <div class="panel-image" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>);">
  26. <div class="panel-image-prop" style="padding-top: <?php echo esc_attr( $ratio ); ?>%"></div>
  27. </div>
  28. <?php endif; ?>
  29. <div class="panel-content">
  30. <div class="wrap">
  31. <header class="entry-header">
  32. <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
  33. <?php lodestar_edit_link( get_the_ID() ); ?>
  34. </header><!-- .entry-header -->
  35. <div class="entry-content">
  36. <?php
  37. /* translators: %s: Name of current post */
  38. the_content( sprintf(
  39. wp_kses( __( 'Continue reading %s <span class="meta-nav">&rarr;</span>', 'lodestar' ), array( 'span' => array( 'class' => array() ) ) ),
  40. the_title( '<span class="screen-reader-text">"', '"</span>', false )
  41. ) );
  42. ?>
  43. </div><!-- .entry-content -->
  44. <?php
  45. // Show portfolio projects
  46. if ( 'templates/portfolio-page.php' === get_page_template_slug() ) :
  47. // show 6 latest portfolio projects
  48. $args = array(
  49. 'post_type' => 'jetpack-portfolio',
  50. 'posts_per_page' => 6,
  51. 'no_found_rows' => true,
  52. );
  53. $project_query = new WP_Query ( $args );
  54. ?>
  55. <?php if ( post_type_exists( 'jetpack-portfolio' ) && $project_query -> have_posts() ) : ?>
  56. <div class="portfolio-projects">
  57. <?php
  58. while ( $project_query -> have_posts() ) : $project_query -> the_post();
  59. get_template_part( 'components/features/portfolio/content', 'portfolio' );
  60. endwhile;
  61. ?>
  62. </div><!-- .portfolio-projects -->
  63. <?php endif; ?>
  64. <?php wp_reset_postdata(); ?>
  65. <?php
  66. // Show testimpnials
  67. elseif ( 'templates/testimonial-page.php' === get_page_template_slug() ) : ?>
  68. <?php
  69. // Show two random testimonials
  70. $args = array(
  71. 'orderby' => 'rand',
  72. 'post_type' => 'jetpack-testimonial',
  73. 'posts_per_page' => 2,
  74. 'no_found_rows' => true,
  75. );
  76. $testimonial_query = new WP_Query ( $args );
  77. ?>
  78. <?php if ( post_type_exists( 'jetpack-testimonial' ) && $testimonial_query -> have_posts() ) : ?>
  79. <div class="testimonials">
  80. <?php
  81. while ( $testimonial_query -> have_posts() ) : $testimonial_query -> the_post();
  82. get_template_part( 'components/features/testimonials/content', 'testimonials' );
  83. endwhile;
  84. ?>
  85. </div><!-- .testimonials -->
  86. <?php endif; ?>
  87. <?php wp_reset_postdata(); ?>
  88. <?php
  89. // Show recent blog posts
  90. // (Note that get_option returns a string, so we're casting the result as an int).
  91. elseif ( get_the_ID() === (int) get_option( 'page_for_posts' ) ) : ?>
  92. <?php // Show four most recent posts.
  93. $args = array(
  94. 'posts_per_page' => 2,
  95. 'post_status' => 'publish',
  96. 'ignore_sticky_posts' => true,
  97. 'no_found_rows' => true,
  98. );
  99. $recent_posts = new WP_Query ( $args );
  100. ?>
  101. <?php if ( $recent_posts->have_posts() ) : ?>
  102. <div class="recent-posts">
  103. <?php
  104. while ( $recent_posts->have_posts() ) : $recent_posts->the_post();
  105. get_template_part( 'components/post/content', 'excerpt' );
  106. endwhile;
  107. ?>
  108. </div><!-- .recent-posts -->
  109. <?php endif; ?>
  110. <?php wp_reset_postdata(); ?>
  111. <?php endif; ?>
  112. </div><!-- .wrap -->
  113. </div><!-- .panel-content -->
  114. </article><!-- #post-## -->