Plugin Directory

Changeset 1049144


Ignore:
Timestamp:
12/19/2014 11:16:54 AM (11 years ago)
Author:
blocknot.es
Message:

Loads parent category image if nothing is found before

Location:
category-featured-images/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • category-featured-images/trunk/category-featured-images.php

    r1041737 r1049144  
    44 * Plugin URI: https://github.com/blocknotes/wordpress_category_featured_images
    55 * Description: Allows to set featured images for categories, posts without a featured image will show the category's image (Posts \ Categories \ Edit category)
    6  * Version: 1.1.2
     6 * Version: 1.1.5
    77 * Author: Mattia Roccoberton
    88 * Author URI: http://blocknot.es
     
    5858            {
    5959                $images = get_option( 'cfi_featured_images' );
     60                $cat = NULL;
    6061                foreach( $categories as $category )
    6162                {
     
    6566                        if( $attachment !== FALSE ) return $attachment[0];
    6667                    }
     68                    if( $cat === NULL ) $cat = $category;
     69                }
     70                if( $cat !== NULL )
     71                {
     72                    $parent = intval( $cat->parent );
     73                    if( $parent > 0 && isset( $images[$parent] ) )
     74                    {
     75                        $attachment = wp_get_attachment_image_src( $images[$parent], $size );
     76                        if( $attachment !== FALSE ) return $attachment[0];
     77                    }
    6778                }
    6879            }
     
    90101            {
    91102                $images = get_option( 'cfi_featured_images' );
     103                $cat = NULL;
    92104                foreach( $categories as $category )
    93105                {
    94106                    if( isset( $images[$category->term_id] ) ) return '<span class="cfi-featured-image">' . wp_get_attachment_image( $images[$category->term_id], $size ) . '</span>';
     107                    if( $cat === NULL ) $cat = $category;
     108                }
     109                if( $cat !== NULL )
     110                {
     111                    $parent = intval( $cat->parent );
     112                    if( $parent > 0 && isset( $images[$parent] ) ) return '<span class="cfi-featured-image">' . wp_get_attachment_image( $images[$parent], $size ) . '</span>';
    95113                }
    96114            }
     
    176194        // Look for a category featured image
    177195            $categories = wp_get_post_categories( $object_id );
    178             if( isset( $categories[0] ) )
    179             {
    180                 $images = get_option( 'cfi_featured_images' );
    181                 if( $images !== FALSE && isset( $images[$categories[0]] ) ) return $images[$categories[0]];
    182             }
     196            $images = get_option( 'cfi_featured_images' );
     197            $cat = NULL;
     198            foreach( $categories as $category )
     199            {
     200                if( isset( $images[$category] ) ) return $images[$category];
     201                if( $cat === NULL ) $cat = $category;
     202            }
     203            if( $cat !== NULL )
     204            {   // Look for the parent category image
     205                $category = get_category( $cat );
     206                if( !empty( $category ) && isset( $category->parent ) )
     207                {
     208                    $parent = intval( $category->parent );
     209                    if( $parent > 0 && isset( $images[$parent] ) ) return $images[$parent];
     210                }
     211            }
     212
    183213            return '';
    184214        }
  • category-featured-images/trunk/readme.txt

    r1041745 r1049144  
    44Donate link: http://www.blocknot.es/home/me/
    55Requires at least: 3.5.0
    6 Tested up to: 4.0
     6Tested up to: 4.1
    77Stable tag: trunk
    88License: GPL3
     
    4141* 'cat_id': get the image URL of a specific category id
    4242
     43Notes:
     44
     45* If a post has more than a category with a featured image the first available is loaded
     46* If a category hasn't a featured image but it has a parent category with a featured image the parent one is loaded
     47
    4348== Installation ==
    4449
     
    5358== Upgrade Notice ==
    5459
     60= 1.1.5 =
     61* Loads parent category image if nothing is found before
    5562= 1.1.2 =
    5663* Added 'cat_id' param to cfi_featured_image_url
     
    6370== Changelog ==
    6471
     72= 1.1.5 =
     73* Loads parent category image if nothing is found before
    6574= 1.1.2 =
    6675* Added 'cat_id' param to cfi_featured_image_url
Note: See TracChangeset for help on using the changeset viewer.