Permalink
Browse files

Merge pull request #1158 from Automattic/add-featured-image-content-o…

…ptions

_s: Add featured images to Post and Pages with the ability to hide them via Content Options.
2 parents efd37d1 + c642776 commit 115dd8209c41669d1c6c173cbe533523bbc73158 @laurelfulford laurelfulford committed Dec 13, 2017
Showing with 47 additions and 1 deletion.
  1. +6 −1 inc/jetpack.php
  2. +35 −0 inc/template-tags.php
  3. +2 −0 template-parts/content-page.php
  4. +2 −0 template-parts/content-search.php
  5. +2 −0 template-parts/content.php
View
@@ -27,14 +27,19 @@ function _s_jetpack_setup() {
// Add theme support for Content Options.
add_theme_support( 'jetpack-content-options', array(
- 'post-details' => array(
+ 'post-details' => array(
'stylesheet' => '_s-style',
'date' => '.posted-on',
'categories' => '.cat-links',
'tags' => '.tags-links',
'author' => '.byline',
'comment' => '.comments-link',
),
+ 'featured-images' => array(
+ 'archive' => true,
+ 'post' => true,
+ 'page' => true,
+ ),
) );
}
add_action( 'after_setup_theme', '_s_jetpack_setup' );
View
@@ -100,3 +100,38 @@ function _s_entry_footer() {
);
}
endif;
+
+if ( ! function_exists( '_s_post_thumbnail' ) ) :
+/**
+ * Displays an optional post thumbnail.
+ *
+ * Wraps the post thumbnail in an anchor element on index views, or a div
+ * element when on single views.
+ */
+function _s_post_thumbnail() {
+ if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
+ return;
+ }
+
+ if ( is_singular() ) :
+ ?>
+
+ <div class="post-thumbnail">
+ <?php the_post_thumbnail(); ?>
+ </div><!-- .post-thumbnail -->
+
+ <?php else : ?>
+
+ <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
+ <?php
+ the_post_thumbnail( 'post-thumbnail', array(
+ 'alt' => the_title_attribute( array(
+ 'echo' => false,
+ ) ),
+ ) );
+ ?>
+ </a>
+
+ <?php endif; // End is_singular().
+}
+endif;
@@ -14,6 +14,8 @@
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
+ <?php _s_post_thumbnail(); ?>
+
<div class="entry-content">
<?php
the_content();
@@ -20,6 +20,8 @@
<?php endif; ?>
</header><!-- .entry-header -->
+ <?php _s_post_thumbnail(); ?>
+
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
@@ -26,6 +26,8 @@
endif; ?>
</header><!-- .entry-header -->
+ <?php _s_post_thumbnail(); ?>
+
<div class="entry-content">
<?php
the_content( sprintf(

0 comments on commit 115dd82

Please sign in to comment.