Community Forums › Forums › Archived Forums › General Discussion › Exclude Single Post Featured Image From Certain Categories
Tagged: feature image, single post
- This topic has 3 replies, 3 voices, and was last updated 9 years, 11 months ago by nunotmp.
-
AuthorPosts
-
November 14, 2014 at 2:41 pm #131560horizonsofchaosParticipant
I'm trying to figure out how to accomplish this task but I've hit a dead end and I'm not sure where to go from here. I used the following code I referenced from one of Brad Dalton's tutorials to show the featured image on Single Posts:
//Featured Image on Single Post add_action( 'genesis_entry_header', 'single_post_featured_image', 15 ); function single_post_featured_image() { if ( ! is_singular( 'post' ) ) return; $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) ); printf( $img ); }
What I'd like to do is have the featured image show on all single posts except for those with the parent category of "Photos." As I understand it this should use a conditional but I just don't know how to write it. Any ideas or any clues on where to look?
http://monstermagicmt.com/test2/November 15, 2014 at 2:58 pm #131654Brad DaltonParticipantNovember 15, 2014 at 3:05 pm #131657horizonsofchaosParticipantThis is the tutorial of yours I referenced: http://wpsites.net/web-design/display-featured-image-before-or-after-entry-title-on-single-posts-pages/
Here is my functions.php code
<?php //* Start the engine include_once( get_template_directory() . '/lib/init.php' ); //* Child theme (do not remove) define( 'CHILD_THEME_NAME', 'Genesis Sample Theme' ); define( 'CHILD_THEME_URL', 'http://www.studiopress.com/' ); define( 'CHILD_THEME_VERSION', '2.1.2' ); // Child theme library require_once(CHILD_DIR.'/lib/structure/lexicon_post.php'); //* Enqueue Google Fonts add_action( 'wp_enqueue_scripts', 'genesis_sample_google_fonts' ); function genesis_sample_google_fonts() { wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Lato:300,400,700', array(), CHILD_THEME_VERSION ); } //* Add HTML5 markup structure add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) ); //* Add viewport meta tag for mobile browsers add_theme_support( 'genesis-responsive-viewport' ); //* Add support for custom background add_theme_support( 'custom-background' ); //* Add support for 3-column footer widgets add_theme_support( 'genesis-footer-widgets', 3 ); // Add new image sizes add_image_size('Slideshow', 600, 300, TRUE); add_image_size('Small Thumbnail', 70, 70, TRUE); add_image_size('Medium Thumbnail', 250, 166, TRUE); add_image_size('Photos Page Thumbnail', 150, 100, TRUE); // Changing excerpt more add_filter('excerpt_more', 'new_excerpt_more'); function new_excerpt_more($more) { return '…<br /><span class="more-link-wrapper"><a href="'.get_permalink().'" class="more-link">Read More</a></span>'; } // Alter Post Byline remove_action('genesis_before_post_content','genesis_post_info'); add_action('genesis_before_post_content','lexicon_post_info'); // Remove Post Meta remove_action('genesis_after_post_content', 'genesis_post_meta'); //* Enqueue sticky menu script add_action( 'wp_enqueue_scripts', 'sp_enqueue_script' ); function sp_enqueue_script() { wp_enqueue_script( 'sample-sticky-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/sticky-menu.js', array( 'jquery' ), '1.0.0' ); } //* Reposition the secondary navigation menu remove_action( 'genesis_after_header', 'genesis_do_subnav' ); add_action( 'genesis_before', 'genesis_do_subnav' ); //Enables use of images in widget title box function genesis_widget_title( $title ) { if( preg_match( '|^https?://|', $title ) ) return "<img src='{$title}' />"; return $title; } add_filter( 'widget_title', 'genesis_widget_title' ); // Register responsive menu script add_action( 'wp_enqueue_scripts', 'genesis_enqueue_scripts' ); /** * Enqueue responsive javascript * @author Ozzy Rodriguez * @todo Change 'prefix' to your theme's prefix */ function genesis_enqueue_scripts() { wp_enqueue_script( 'genesis-responsive-menu', get_stylesheet_directory_uri() . '/lib/js/responsive-menu.js', array( 'jquery' ), '1.0.0', true ); // Change 'prefix' to your theme's prefix } //Featured Image on Single Post add_action( 'genesis_entry_header', 'single_post_featured_image', 15 ); function single_post_featured_image( ) { if ( ! is_singular( 'post' ) ) return; $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) ); printf( $img ); } //Featured Image on Category Archive //Home Page News Posts add_action( 'genesis_before', 'child_conditional_actions' ); function child_conditional_actions() { if( is_category( 'photos' ) || is_category( '2015-photos' ) || is_category( '2014-photos' ) || is_category( '2013-photos' ) || is_category( '2012-photos' ) || is_category( '2011-photos' ) || is_category( '2010-photos' ) || is_category( '2009-photos' ) || is_category( '2008-photos' ) || is_category( '2007-photos' ) || is_category( '2006-photos' ) || is_category( '2005-photos' ) || is_category( '2004-photos' ) ) { remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); add_action( 'genesis_entry_content', 'photos_archive_featured_image', 8 ); } } function photos_archive_featured_image() { $img = genesis_get_image( array( 'format' => 'html', 'size' => 'Photos Page Thumbnail', 'attr' => array( 'class' => 'alignleft post-image' ) ) ); printf( $img ); }
November 15, 2014 at 3:18 pm #131660nunotmpMemberYou need to use the conditional
in_category()
so this should work.function single_post_featured_image() { if ( ! is_singular( 'post' ) || in_category( 'photos' ) ) return; $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) ); printf( $img ); }
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.