content-single.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Template part for displaying posts.
  4. *
  5. * @link https://codex.wordpress.org/Template_Hierarchy
  6. *
  7. * @package AltoFocus
  8. */
  9. ?>
  10. <?php
  11. /**
  12. * Display A Gallery
  13. *
  14. * - Only display gallery when content has [gallery] shortcode and type = 'slideshow'
  15. * - Allow single post, featured image Content Options to force shortcode default behavior
  16. *
  17. * src: http://wordpress.stackexchange.com/questions/121489/split-content-and-gallery/121508
  18. * src: http://stackoverflow.com/questions/17224100/wordpress-remove-shortcode-and-save-for-use-elsewhere
  19. */
  20. // Reset content width for featured image/gallery
  21. $content_width = 1200;
  22. // Look for shortcodes in content
  23. $content = get_the_content();
  24. $pattern = get_shortcode_regex();
  25. $get_image_post = get_option( 'jetpack_content_featured_images_post' );
  26. $content_option_override = ( empty ( $get_image_post ) ) ? '0' : '1';
  27. preg_match( '/' . $pattern . '/s', $content, $matches );
  28. // Account for Content Option settings
  29. if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) || ! empty ( $get_image_post ) ) {
  30. $content_option_override = '1';
  31. } else {
  32. $content_option_override = '0';
  33. }
  34. // If content has a gallery with the slideshow type, display that instead of the featured image.
  35. if ( has_shortcode( $content, 'gallery' ) && ( strpos( $matches[0], 'slideshow' ) !== false ) && $content_option_override == '1' ) :
  36. if ( $matches ) {
  37. if ( is_array( $matches ) && $matches[2] == 'gallery' ) {
  38. // Remove gallery markup from content (effects .entry-content below)
  39. $content = altofocus_strip_override_shortcode( $content );
  40. // Filter default gallery with custom full-width flexslider gallery. See: extras.php
  41. add_filter( 'post_gallery', 'altofocus_slideshow_gallery_filter', 10, 2);
  42. $shortcode = $matches[0];
  43. $output = do_shortcode( $shortcode );
  44. }
  45. }
  46. // Output flexslider_gallery as a slideshow
  47. echo "\t\t\t<div class=\"entry-media\">
  48. \t<div class=\"entry-media-wrap\">
  49. \t\t" . $output . "
  50. \t</div>
  51. </div>";
  52. /**
  53. * OR display regular featured image
  54. */
  55. elseif ( '' != altofocus_has_post_thumbnail() ) : ?>
  56. <figure class="entry-media">
  57. <div class="entry-media-wrap">
  58. <?php the_post_thumbnail( 'altofocus-post-featured-image' ); ?>
  59. </div>
  60. </figure>
  61. <?php endif; ?>
  62. <?php get_template_part( 'components/navigation/navigation', 'fixed' ); ?>
  63. <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  64. <header class="entry-header">
  65. <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
  66. <?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
  67. <div class="comments-link">
  68. <?php comments_popup_link( number_format_i18n( get_comments_number() ), number_format_i18n( get_comments_number() ), number_format_i18n( get_comments_number() ) ); ?>
  69. <svg class="comment-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50">
  70. <path class="path" d="M49.5,25c0-13.5-11-24.5-24.5-24.5S0.5,11.5,0.5,25s11,24.5,24.5,24.5h24.5l-7.2-7.2 C46.8,37.9,49.5,31.8,49.5,25z"/>
  71. </svg>
  72. </div>
  73. <?php endif; ?>
  74. <?php get_template_part( 'components/post/content', 'meta' ); ?>
  75. </header>
  76. <div class="entry-content">
  77. <?php // Display the content after reseting the content width to global
  78. $content_width = $GLOBALS['content_width'];
  79. $content = apply_filters( 'the_content', $content );
  80. echo $content;
  81. wp_link_pages( array(
  82. 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'altofocus' ),
  83. 'after' => '</div>',
  84. ) );
  85. ?>
  86. </div>
  87. <?php get_template_part( 'components/post/content', 'footer' ); ?>
  88. </article><!-- #post-## -->