front-page.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * The front page template file.
  4. *
  5. * If the user has selected a static page for their homepage, this is what will
  6. * appear.
  7. * Learn more: http://codex.wordpress.org/Template_Hierarchy
  8. *
  9. * @package Affinity
  10. */
  11. if ( 'posts' == get_option( 'show_on_front' ) ) :
  12. get_template_part( 'index' );
  13. else :
  14. get_header(); ?>
  15. <div id="primary" class="content-area">
  16. <main id="main" class="site-main" role="main">
  17. <?php // Show the selected frontpage content
  18. if ( have_posts() ) :
  19. while ( have_posts() ) : the_post();
  20. get_template_part( 'components/page/content', 'page' );
  21. endwhile;
  22. else : // I'm not sure it's possible to have no posts when this page is shown, but WTH
  23. get_template_part( 'components/posts/content', 'none' );
  24. endif;
  25. ?>
  26. <?php
  27. // Get each of our panels and show the post data
  28. $panels = array( '1', '2', '3', '4', '5' );
  29. $titles = array();
  30. global $affinitycounter; //Used in content-frontpage.php
  31. if ( 0 !== affinity_panel_count() ) : //If we have pages to show...
  32. $affinitycounter = 1;
  33. foreach ( $panels as $panel ) :
  34. if ( get_theme_mod( 'affinity_panel' . $panel ) ) :
  35. $post = get_post( get_theme_mod( 'affinity_panel' . $panel ) );
  36. setup_postdata( $post );
  37. if ( 'publish' === get_post_status() ) :
  38. // echo get_post_status();
  39. set_query_var( 'affinity_panel', $panel );
  40. get_template_part( 'components/page/content', 'frontpage' );
  41. $titles[] = get_the_title(); //Put page titles in an array for use in navigation
  42. wp_reset_postdata();
  43. $affinitycounter++;
  44. else :
  45. wp_reset_postdata();
  46. endif; // if ( 'publish' === get_post_status() )
  47. endif; // if ( get_theme_mod( 'affinity_panel' . $panel ) )
  48. endforeach; // foreach ( $panels as $panel )
  49. /* In-page navigation */
  50. echo '<ul class="panel-navigation">';
  51. echo '<li><a class="panel0" href="#page"><span class="sep">&diams;</span><span class="hidden">' . esc_html__( 'Back to Top', 'affinity' ) . '</span></a></li>';
  52. $counter = 0;
  53. foreach ( $panels as $panel ) : //Iterate over each panel and grab titles from $titles[] defined in the previous loop
  54. if ( get_theme_mod( 'affinity_panel' . $panel ) ) : //If the theme mod is set...
  55. $post = get_post( get_theme_mod( 'affinity_panel' . $panel ) );
  56. setup_postdata( $post );
  57. if ( 'publish' === get_post_status() ) :
  58. echo '<li><a class="panel' . $panel . '" href="#panel' . $panel . '"><span class="sep">&diams;</span><span class="hidden">' . $titles[$counter] . '</span></a></li>';
  59. wp_reset_postdata();
  60. $counter++;
  61. else :
  62. wp_reset_postdata();
  63. endif; // if ( 'publish' === get_post_status() )
  64. endif;
  65. endforeach; // foreach ( $panels as $panel )
  66. echo '</ul><!-- .panel-navigation -->';
  67. endif; // if ( 0 !== affinity_panel_count() )
  68. ?>
  69. </main><!-- #main -->
  70. </div><!-- #primary -->
  71. <?php get_footer();
  72. endif; ?>