Remove featured img on multiple blog page posts that are in a specific category

Community Forums Forums Design Tips and Tricks Remove featured img on multiple blog page posts that are in a specific category

This topic is: resolved

This topic contains 4 replies, has 2 voices, and was last updated by  tornado 1 year, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #52868

    tornado
    Participant
    Post count: 35

    Hi folks.

    I have used the following code to remove the featured image on a blog page for posts that are in a specific category. However, I don’t know how to add MORE categories (as I have multiple blog pages).

    You will see that I have inserted category ’20′ in if ( ! has_category( 20, $post ) ) and I need to add category 21 and 22.

    add_action( 'genesis_before_post' , 'wps_no_featured_image' );
    add_action( 'genesis_after_post_content' , 'wps_no_featured_image' );
    /*
     * Remove featured image from certain posts.
     * 
     * Stops featured image from displayed on the Small Group Show category (126) on 
     * the blog page.
     * 
     * @author Travis Smith
     * @link   http://wpsmith.net/2012/genesis/how-to-hide-the-featured-image-of-a-specific-category-on-the-blog-page-in-genesis/
     *
     * @global stdClass $post Post object.
     * 
     * @return null Returns early if post is not in our chosen category.
     */
    function wps_no_featured_image() {
     
        global $post;
     
        <strong>if ( ! has_category( 20, $post ) )</strong>
    	return;
     
        if ( 'genesis_before_post' == current_filter() )
            remove_action( 'genesis_post_content', 'genesis_do_post_image' );
        elseif ( 'genesis_after_post_content' == current_filter() )
            add_action( 'genesis_before_post_content', 'genesis_do_post_image' );
     
    }

    Any help would be awesome.

    Cheers.

    G

    #52885

    braddalton
    Participant
    Post count: 10565

    You’ll need an array:

    [php]
    if (! in_category( array( 20,21,22 ) ) )
    [/php]

    Not sure why you use has_category but change the code if that’s what you want to use.


    #52924

    tornado
    Participant
    Post count: 35

    Brad, that’s awesome. Thank you! Used your code entirely.

    I really appreciate it.

    G

    #52926

    braddalton
    Participant
    Post count: 10565

    You’re welcome.

    Please mark this as resolved. Thanks


    #55677

    tornado
    Participant
    Post count: 35
    This reply has been marked as private.
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Remove featured img on multiple blog page posts that are in a specific category’ is closed to new replies.