content-page-highlight.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * The template for displaying featured content on the front page
  4. *
  5. * @package TextBook
  6. */
  7. /**
  8. * Adds a class to the featured page so that,
  9. * the header image is positioned correctly
  10. */
  11. $offset_header = '';
  12. if ( ! get_header_image() ) {
  13. $offset_header = ' offset';
  14. }
  15. // Featured page output.
  16. $featured_page_id = absint( get_theme_mod( 'featured_page' ) );
  17. if ( $featured_page_id ) :
  18. $featured_page = new WP_Query( array(
  19. 'post_type' => 'page',
  20. 'page_id' => $featured_page_id,
  21. 'posts_per_page' => 1,
  22. 'no_found_rows' => true,
  23. ) );
  24. if ( $featured_page->have_posts() ) :
  25. ?>
  26. <div class="featured-page-highlight<?php echo $offset_header; ?>">
  27. <?php while ( $featured_page->have_posts() ) : $featured_page->the_post(); ?>
  28. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  29. <?php the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
  30. <div class="entry-content entry-summary">
  31. <?php
  32. $continue_reading = sprintf(
  33. /* translators: %s: Name of current post. */
  34. wp_kses( __( 'Continue reading %s', 'textbook' ), array( 'span' => array( 'class' => array() ) ) ),
  35. the_title( '<span class="screen-reader-text">"', '"</span>', false )
  36. );
  37. $content = get_the_content();
  38. $content = strip_shortcodes( $content );
  39. $content = wp_trim_words( $content, '50' );
  40. $content .= '<a class="more-link" href="' . esc_url( get_permalink() ) . '">' . $continue_reading . '</a>';
  41. echo apply_filters( 'the_content', $content );
  42. ?>
  43. </div>
  44. </article>
  45. <?php
  46. endwhile;
  47. wp_reset_postdata();
  48. ?>
  49. </div>
  50. <?php endif; // end if ( $featured_page->have_posts() )
  51. endif; // end if ( $featured_page_id )