excerpt display optional

This commit is contained in:
Robin Cornett
2014-10-28 18:12:44 -04:00
parent abedb24f45
commit aca975db09
10 changed files with 309 additions and 62 deletions
@@ -19,9 +19,10 @@ class Display_Featured_Image_Genesis_Common {
global $post;
// variables internal to this function
$frontpage = get_option( 'show_on_front' ); // either 'posts' or 'page'
$postspage = get_option( 'page_for_posts' );
$postspage_image = get_post_thumbnail_id( $postspage );
$frontpage = get_option( 'show_on_front' ); // either 'posts' or 'page'
$postspage = get_option( 'page_for_posts' );
$move_excerpts = get_option( 'displayfeaturedimage_excerpts' );
$postspage_image = get_post_thumbnail_id( $postspage );
if ( is_singular() ) {
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'displayfeaturedimage_backstretch' );
}
@@ -49,10 +50,30 @@ class Display_Featured_Image_Genesis_Common {
// Set Post/Page Title
if ( is_singular() && ! is_front_page() ) {
$item->title = get_the_title();
if ( has_excerpt() ) {
$item->description = get_the_excerpt();
}
}
elseif ( is_home() && $frontpage === 'page' ) {
$item->title = get_post( $postspage )->post_title;
}
elseif ( is_category() || is_tag() || is_tax() ) {
$term = is_tax() ? get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) : get_queried_object();
if ( ! $term || ! isset( $term->meta ) ) {
return;
}
$item->title = $term->meta['headline'];
$item->description = $term->meta['intro_text'];
}
elseif ( is_author() ) {
$item->title = get_the_author_meta( 'headline', (int) get_query_var( 'author' ) );
$item->description = get_the_author_meta( 'intro_text', (int) get_query_var( 'author' ) );
}
elseif ( is_post_type_archive() && genesis_has_post_type_archive_support() && !empty( $item->fallback ) ) {
$item->title = genesis_get_cpt_option( 'headline' );
$item->description = genesis_get_cpt_option( 'intro_text' );
}
else {
$item->title = '';
}
@@ -0,0 +1,136 @@
<?php
class Display_Featured_Image_Genesis_Description {
/**
* Show optional excerpt on single posts.
*
* If it's not a single post, nothing happens.
*
* If there's an excerpt and the move excerpts option is selected, it runs through `wpautop()` before being added to a div.
*
* @since 1.3.0
*
* @return null Return early if not a single post with an excerpt.
*/
public static function do_excerpt() {
if ( !is_single() || !has_excerpt() ) {
return;
}
else {
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
printf( '<div class="excerpt"><h1 class="entry-title">%s</h1>%s</div>', $item->title, $item->description );
}
}
/**
* Add custom description to category / tag / taxonomy archive pages.
*
* If the page is not a category, tag or taxonomy term archive, or we're not on the first page, or there's no term, or
* no term meta set, then nothing extra is displayed.
*
* If there's a description to display, it runs through `wpautop()` before being added to a div.
*
* @since 1.3.0
*
* @global WP_Query $wp_query Query object.
*
* @return null Return early if not the correct archive page, not page one, or no term meta is set.
*/
public static function do_tax_description() {
global $wp_query;
if ( ! is_category() && ! is_tag() && ! is_tax() )
return;
if ( get_query_var( 'paged' ) >= 2 )
return;
$term = is_tax() ? get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) : $wp_query->get_queried_object();
if ( ! $term || ! isset( $term->meta ) )
return;
$intro_text = '';
if ( $term->meta['intro_text'] )
$intro_text = apply_filters( 'genesis_term_intro_text_output', $term->meta['intro_text'] );
if ( $intro_text )
printf( '<div class="archive-description taxonomy-description">%s</div>', $intro_text );
}
/**
* Add custom headline and description to author archive pages.
*
* If we're not on an author archive page, or not on page 1, then nothing extra is displayed.
*
* If there's a custom headline to display, it is marked up as a level 1 heading.
*
* If there's a description (intro text) to display, it is run through `wpautop()` before being added to a div.
*
* @since 1.4.0
*
* @return null Return early if not author archive or not page one.
*/
public static function do_author_description() {
if ( ! is_author() )
return;
if ( get_query_var( 'paged' ) >= 2 )
return;
$intro_text = get_the_author_meta( 'intro_text', (int) get_query_var( 'author' ) );
$intro_text = $intro_text ? apply_filters( 'genesis_author_intro_text_output', $intro_text ) : '';
if ( $intro_text )
printf( '<div class="archive-description author-description">%s</div>', $intro_text );
}
/**
* Add custom headline and description to relevant custom post type archive pages.
*
* If we're not on a post type archive page, or not on page 1, then nothing extra is displayed.
*
* If there's a custom headline to display, it is marked up as a level 1 heading.
*
* If there's a description (intro text) to display, it is run through wpautop() before being added to a div.
*
* @since 2.0.0
*
* @uses genesis_has_post_type_archive_support() Check if a post type should potentially support an archive setting page.
* @uses genesis_get_cpt_option() Get list of custom post types which need an archive settings page.
*
* @return null Return early if not on relevant post type archive.
*/
public static function do_cpt_archive_description() {
if ( ! is_post_type_archive() || ! genesis_has_post_type_archive_support() )
return;
if ( get_query_var( 'paged' ) >= 2 )
return;
$intro_text = genesis_get_cpt_option( 'intro_text' );
$intro_text = $intro_text ? apply_filters( 'genesis_cpt_archive_intro_text_output', $intro_text ) : '';
if ( $intro_text )
printf( '<div class="archive-description cpt-archive-description">%s</div>', $intro_text );
}
}
@@ -49,6 +49,7 @@ class Display_Featured_Image_Genesis_Output {
) );
add_action( 'genesis_after_header', array( $this, 'do_backstretch_image_title' ) );
add_action( 'genesis_before_loop', array( $this, 'move_titles' ) );
}
@@ -96,30 +97,36 @@ class Display_Featured_Image_Genesis_Output {
remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML
}
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
echo '<div class="big-leader"><div class="wrap">';
if ( !empty( $item->title ) ) {
$excerpt = get_the_excerpt();
if ( is_single() && has_excerpt() && !in_array( get_post_type(), Display_Featured_Image_Genesis_Common::omit_excerpt() ) ) {
echo '<div class="entry-header">';
echo '<h1 class="entry-title">' . $item->title . '</h1>';
echo wpautop( $excerpt );
echo '</div>';
$move_excerpts = get_option( 'displayfeaturedimage_excerpts' );
if ( $move_excerpts ) {
if ( !empty( $item->description ) && !in_array( get_post_type(), Display_Featured_Image_Genesis_Common::omit_excerpt() ) ) {
Display_Featured_Image_Genesis_Description::do_excerpt();
genesis_do_taxonomy_title_description();
genesis_do_author_title_description();
genesis_do_cpt_archive_title_description();
}
else {
echo '<h1 class="entry-title featured-image-overlay">' . $item->title . '</h1>';
}
}
if ( is_category() || is_tag() || is_tax() ) {
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
genesis_do_taxonomy_title_description();
}
elseif ( is_author() ) {
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
genesis_do_author_title_description();
}
elseif ( is_post_type_archive() ) {
else {
if ( !empty( $item->title ) ) {
echo '<h1 class="entry-title featured-image-overlay">' . $item->title . '</h1>';
}
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
genesis_do_cpt_archive_title_description();
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
}
echo '</div></div>';
}
@@ -135,4 +142,26 @@ class Display_Featured_Image_Genesis_Output {
echo get_the_post_thumbnail( $post->ID, 'large', array( 'class' => 'aligncenter featured', 'alt' => the_title_attribute( 'echo=0' ) ) );
}
/**
* Separate archive titles from descriptions. Titles show in leader image
* area; descriptions show before loop.
*
* @return descriptions
*
* @since 1.3.0
*
*/
public function move_titles() {
$move_excerpts = get_option( 'displayfeaturedimage_excerpts' );
if ( $move_excerpts ) {
return;
}
else {
Display_Featured_Image_Genesis_Description::do_tax_description();
Display_Featured_Image_Genesis_Description::do_author_description();
Display_Featured_Image_Genesis_Description::do_cpt_archive_description();
}
}
}
@@ -18,6 +18,7 @@ class Display_Featured_Image_Genesis_Settings {
public function register_settings() {
register_setting( 'media', 'displayfeaturedimage_less_header', 'absint' );
register_setting( 'media', 'displayfeaturedimage_default', array( $this, 'validate_image' ) );
register_setting( 'media', 'displayfeaturedimage_excerpts', array( $this, 'one_zero' ) );
add_settings_section(
@@ -43,6 +44,14 @@ class Display_Featured_Image_Genesis_Settings {
'display_featured_image_section'
);
add_settings_field(
'displayfeaturedimage_excerpts',
'<label for="displayfeaturedimage_excerpts">' . __( 'Move Excerpts/Archive Descriptions', 'display-featured-image-genesis' ) . '</label>',
array( $this, 'move_excerpts' ),
'media',
'display_featured_image_section'
);
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
@@ -54,7 +63,7 @@ class Display_Featured_Image_Genesis_Settings {
* @since 1.1.0
*/
public function section_description() {
echo '<p>' . __( 'The Display Featured Image for Genesis plugin has two optional settings: 1) change the height of the backstretch effect, and 2) set a default backstretch image to use if no featured image is set.', 'display-featured-image-genesis' ) . '</p>';
echo '<p>' . __( 'The Display Featured Image for Genesis plugin has three optional settings. Check the Help tab for more information. ', 'display-featured-image-genesis' ) . '</p>';
}
/**
@@ -95,13 +104,25 @@ class Display_Featured_Image_Genesis_Settings {
) . '</p>';
}
/**
* move excerpts to leader image area
* @return 0 1 checkbox
*
* @since 1.3.0
*/
public function move_excerpts() {
$value = get_option( 'displayfeaturedimage_excerpts' );
echo '<input type="checkbox" name="displayfeaturedimage_excerpts" id="displayfeaturedimage_excerpts" value="1"' . checked( 1, $value, false ) . ' class="code" /> <label for="displayfeaturedimage_excerpts">' . __( 'Move excerpts (if used) on single pages and move archive/taxonomy descriptions to overlay the Featured Image.', 'display-featured-image-genesis' ) . '</label>';
}
/**
* Returns previous value for image if not correct file type/size
* @param string $new_value New value
* @return string New or previous value, depending on allowed image size.
* @since 1.2.2
*/
function validate_image( $new_value ) {
public function validate_image( $new_value ) {
// not using get_image_variables since we need to check before commit to option
$new_value = esc_url( $new_value );
@@ -140,7 +161,7 @@ class Display_Featured_Image_Genesis_Settings {
* returns file extension
* @since 1.2.2
*/
private function get_file_ext( $file ) {
protected function get_file_ext( $file ) {
$parsed = @parse_url( $file, PHP_URL_PATH );
return $parsed ? strtolower( pathinfo( $parsed, PATHINFO_EXTENSION ) ) : false;
}
@@ -150,7 +171,7 @@ class Display_Featured_Image_Genesis_Settings {
* @return file check file extension against list
* @since 1.2.2
*/
private function is_valid_img_ext( $file ) {
protected function is_valid_img_ext( $file ) {
$file_ext = $this->get_file_ext( $file );
$this->valid = empty( $this->valid )
@@ -160,6 +181,20 @@ class Display_Featured_Image_Genesis_Settings {
return ( $file_ext && in_array( $file_ext, $this->valid ) );
}
/**
* Returns a 1 or 0, for all truthy / falsy values.
*
* Uses double casting. First, we cast to bool, then to integer.
*
* @since 1.3.0
*
* @param mixed $new_value Should ideally be a 1 or 0 integer passed in
* @return integer 1 or 0.
*/
public function one_zero( $new_value ) {
return (int) (bool) $new_value;
}
/**
* Help tab for media screen
* @return help tab with verbose information for plugin
@@ -171,7 +206,8 @@ class Display_Featured_Image_Genesis_Settings {
$large = get_option( 'large_size_w' );
$displayfeaturedimage_help =
'<h3>' . __( 'Reducto!', 'display-featured-image-genesis' ) . '</h3>' .
'<p>' . __( 'Display Featured Image for Genesis has three optional settings:', 'display-featured-image-genesis' ) . '</p>' .
'<h3>' . __( 'Height', 'display-featured-image-genesis' ) . '</h3>' .
'<p>' . __( 'Depending on how your header/nav are set up, or if you just do not want your backstretch image to extend to the bottom of the user screen, you may want to change this number. It will raise the bottom line of the backstretch image, making it shorter.', 'display-featured-image-genesis' ) . '</p>' .
'<h3>' . __( 'Set a Default Featured Image', 'display-featured-image-genesis' ) . '</h3>' .
@@ -179,7 +215,9 @@ class Display_Featured_Image_Genesis_Settings {
'<p>' . sprintf(
__( 'Supported file types are: jpg, jpeg, png, and gif. The image must be at least %1$s pixels wide.', 'display-featured-image-genesis' ),
$large+1
) . '</p>';
) . '</p>' .
'<h3>' . __( 'Move Excerpts/Archive Descriptions', 'display-featured-image-genesis' ) . '</h3>' .
'<p>' . __( 'By default, archive descriptions (set on the Genesis Archive Settings pages) show below the Default Featured Image, while the archive title displays on top of the image. If you check this box, archives with both a Headline and Intro Text will output both in a box overlaying the Featured Image. Posts which use an optional Excerpt will behave the same way.', 'display-featured-image-genesis' ) . '</p>';
$screen->add_help_tab( array(
'id' => 'displayfeaturedimage-help',
@@ -16,8 +16,9 @@
*/
class Display_Featured_Image_Genesis {
function __construct( $common, $output, $settings ) {
function __construct( $common, $description, $output, $settings ) {
$this->common = $common;
$this->archive = $description;
$this->output = $output;
$this->settings = $settings;
}
@@ -1,6 +1,5 @@
.has-leader .site-inner {
margin-top: 0;
padding-top: 0;
}
.big-leader {
@@ -20,7 +19,7 @@
text-align: center;
}
.big-leader .entry-header,
.big-leader .excerpt,
.big-leader .archive-description {
background: rgba(255,255,255,.85);
color: #333;