浏览代码

Varia: Restore featured images for pages, add support for Jetpack content-options.

Allan Cole 5 年之前
父节点
当前提交
6d6f41c0fd
共有 4 个文件被更改,包括 89 次插入5 次删除
  1. 5 0
      varia/functions.php
  2. 78 0
      varia/inc/jetpack.php
  3. 4 5
      varia/inc/template-tags.php
  4. 2 0
      varia/template-parts/content/content-page.php

+ 5 - 0
varia/functions.php

@@ -317,3 +317,8 @@ require get_template_directory() . '/inc/icon-functions.php';
  * Custom template tags for the theme.
  * Custom template tags for the theme.
  */
  */
 require get_template_directory() . '/inc/template-tags.php';
 require get_template_directory() . '/inc/template-tags.php';
+
+/*
+ * Load Jetpack compatibility file.
+ */
+require get_template_directory() . '/inc/jetpack.php';

+ 78 - 0
varia/inc/jetpack.php

@@ -0,0 +1,78 @@
+<?php
+/**
+ * Jetpack Compatibility File
+ * See: https://jetpack.me/
+ *
+ * @package Varia
+ */
+
+/**
+ * Jetpack setup function.
+ *
+ * See: https://jetpack.com/support/content-options/
+ */
+function varia_jetpack_setup() {
+
+	add_theme_support( 'jetpack-content-options',
+		array(
+				'blog-display'       => 'content', // the default setting of the theme: 'content', 'excerpt' or array( 'content', 'excerpt' ) for themes mixing both display.
+				'author-bio'         => false, // display or not the author bio: true or false.
+				'author-bio-default' => false, // the default setting of the author bio, if it's being displayed or not: true or false (only required if false).
+				'post-details'       => array(
+				'stylesheet'      => 'varia-style', // name of the theme's stylesheet.
+				'date'            => '.posted-on', // a CSS selector matching the elements that display the post date.
+				'categories'      => '.cat-links', // a CSS selector matching the elements that display the post categories.
+				'tags'            => '.tags-links', // a CSS selector matching the elements that display the post tags.
+				'author'          => '.byline', // a CSS selector matching the elements that display the post author.
+				'comment'         => '.comments-link', // a CSS selector matching the elements that display the comment link.
+			),
+				'featured-images'    => array(
+				'archive'         => true, // enable or not the featured image check for archive pages: true or false.
+				'archive-default' => true, // the default setting of the featured image on archive pages, if it's being displayed or not: true or false (only required if false).
+				'post'            => true, // enable or not the featured image check for single posts: true or false.
+				'post-default'    => false, // the default setting of the featured image on single posts, if it's being displayed or not: true or false (only required if false).
+				'page'            => true, // enable or not the featured image check for single pages: true or false.
+				'page-default'    => false, // the default setting of the featured image on single pages, if it's being displayed or not: true or false (only required if false).
+			),
+		)
+	);
+}
+add_action( 'after_setup_theme', 'varia_jetpack_setup' );
+
+/**
+ * Custom function to check for a post thumbnail;
+ * If Jetpack is not available, fall back to has_post_thumbnail()
+ */
+function varia_has_post_thumbnail( $post = null ) {
+	if ( function_exists( 'jetpack_has_featured_image' ) ) {
+		return jetpack_has_featured_image( $post );
+	} else {
+		return has_post_thumbnail( $post );
+	}
+}
+
+/**
+ * Display a Featured Image on archive pages if option is ticked.
+ */
+function varia_jetpack_featured_image_archive_display() {
+    if ( ! function_exists( 'jetpack_featured_images_remove_post_thumbnail' ) ) {
+        return false;
+    } else {
+        $options         = get_theme_support( 'jetpack-content-options' );
+        $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;
+
+        $settings = array(
+            'archive-default' => ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1,
+        );
+
+        $settings = array_merge( $settings, array(
+            'archive-option'  => get_option( 'jetpack_content_featured_images_archive', $settings['archive-default'] ),
+        ) );
+
+        if ( $settings['archive-option'] ) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+}

+ 4 - 5
varia/inc/template-tags.php

@@ -201,8 +201,7 @@ if ( ! function_exists( 'varia_post_thumbnail' ) ) :
 	/**
 	/**
 	 * Displays an optional 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.
+	 * Wraps the post thumbnail in an anchor element on index views
 	 */
 	 */
 	function varia_post_thumbnail() {
 	function varia_post_thumbnail() {
 		if ( ! varia_can_show_post_thumbnail() ) {
 		if ( ! varia_can_show_post_thumbnail() ) {
@@ -212,7 +211,7 @@ if ( ! function_exists( 'varia_post_thumbnail' ) ) :
 		if ( is_singular() ) :
 		if ( is_singular() ) :
 			?>
 			?>
 
 
-			<figure class="post-thumbnail">
+			<figure class="post-thumbnail responsive-max-width">
 				<?php the_post_thumbnail(); ?>
 				<?php the_post_thumbnail(); ?>
 			</figure><!-- .post-thumbnail -->
 			</figure><!-- .post-thumbnail -->
 
 
@@ -220,8 +219,8 @@ if ( ! function_exists( 'varia_post_thumbnail' ) ) :
 		else :
 		else :
 		?>
 		?>
 
 
-			<figure class="post-thumbnail">
-				<a class="post-thumbnail-inner alignwide" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
+			<figure class="post-thumbnail responsive-max-width">
+				<a class="post-thumbnail-inner" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
 					<?php the_post_thumbnail( 'post-thumbnail' ); ?>
 					<?php the_post_thumbnail( 'post-thumbnail' ); ?>
 				</a>
 				</a>
 			</figure>
 			</figure>

+ 2 - 0
varia/template-parts/content/content-page.php

@@ -17,6 +17,8 @@
 		<?php get_template_part( 'template-parts/header/entry', 'header' ); ?>
 		<?php get_template_part( 'template-parts/header/entry', 'header' ); ?>
 	</header>
 	</header>
 
 
+	<?php varia_post_thumbnail(); ?>
+
 	<div class="entry-content">
 	<div class="entry-content">
 		<?php
 		<?php
 		the_content();
 		the_content();