Plugin Directory

Changeset 1046236


Ignore:
Timestamp:
12/16/2014 10:22:55 PM (11 years ago)
Author:
WPBackOffice
Message:

updating to 1.1.1

Location:
woocommerce-category-banner/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-category-banner/trunk/readme.txt

    r907082 r1046236  
    44Donate Link: http://wpbackoffice.com/plugins/woocommerce-category-banner/
    55Requires at least: 2.3
    6 Tested up to: 3.9
    7 Stable tag: 1.1.0
     6Tested up to: 4.0.1
     7Stable tag: 1.1.1
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1919* No configuration needed, just install and start using
    2020* Supports an image for each category
     21* Custom product category positions with a template tag for including the image in a custom area in your custom product category template.
    2122* Support a link for each category / banner image
    2223
     
    28294. That's it, your banner should now be displaying on your category archive page.
    29305. Remove image by deleting the url from the edit category page.
     31
     32You can hide the automatic image placement by unchecking "Automatically insert banner above main content"
     33
     34You can then place the template tag wcb_show_category_banner() in your custom category template to customize the position of the image in your markup. Note - this tag must be placed on category templates - not product templates.
    3035
    3136[Plugin's Official Documentation and Support Page](http://wpbackoffice.com/plugins/woocommerce-category-banner/)
     
    5156== Changelog ==
    5257
     58= 1.1.1 =
     59* Adding Template tag for custom banner position for custom product category templates.
    5360
    5461= 1.1.0 =
  • woocommerce-category-banner/trunk/woocommerce-category-banner.php

    r907086 r1046236  
    44Plugin URI: http://www.wpbackoffice.com/plugins/woocommerce-category-banner/
    55Description: Place a custom banner and link at the top of your product category pages. Easily update the image through your product category edit page.
    6 Version: 1.1.0
     6Version: 1.1.1
    77Author: WP BackOffice
    88Author URI: http://www.wpbackoffice.com
     
    1616   
    1717    public function __construct() {
    18        
     18
     19        global $woocommerce;
     20        global $wp_query;
     21
    1922        // Add Scripts and styles       
    2023        add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_and_styles' ) );
     
    2629        add_action( 'edited_product_cat', array( $this, 'wcb_product_cat_save_taxonomy_custom_fields'), 10, 2 ); 
    2730
    28         // Add a banner image based on category taxonomy image
     31        // Add a banner image based on category taxonomy image, only if it's set to auto show (default)
    2932        add_action( 'woocommerce_before_main_content', array( $this, 'wcb_show_category_banner'), 30 );
     33
    3034    }
    3135
     
    7781        else
    7882            $banner_link = null;
    79            
     83         
     84        // Get auto display setting.
     85        if ( (isset( $term_meta['auto_display_banner']) && $term_meta['auto_display_banner'] == 'on') || !isset( $term_meta['auto_display_banner']) ) {
     86            $auto_display_banner = true;
     87        } else {
     88            $auto_display_banner = false;
     89        }
     90
    8091        ?> 
    8192       
     
    110121            </td> 
    111122        </tr>
     123        <tr class="form-field auto_display_banner"> 
     124            <th scope="row" valign="top"> 
     125                <label for="auto_display_banner"><?php _e('Automatically insert banner above main content'); ?></label> 
     126            </th> 
     127            <td> 
     128                <fieldset>
     129                <input name="term_meta[auto_display_banner]" type="checkbox" value="on" class="auto_display_banner" <?php if($auto_display_banner) echo " checked "; ?>/>
     130                <label class="auto_display_banner_label" for="auto_display_banner"><em>If you want to display the banner in a custom spot on your category page, you can deselect this checkbox and use the wcb_show_category_banner() in your category template to dictate where it will appear.</em></label>     
     131                </fieldset>
     132            </td> 
     133        </tr>
    112134         
    113135    <?php 
     
    120142            $t_id = $term_id; 
    121143            $term_meta = get_option( "taxonomy_term_$t_id" ); 
    122             $cat_keys = array_keys( $_POST['term_meta'] ); 
    123 
    124                 foreach ( $cat_keys as $key ){ 
    125                 if ( isset( $_POST['term_meta'][$key] ) ){ 
    126                     $term_meta[$key] = $_POST['term_meta'][$key]; 
     144            $posted_term_meta = $_POST['term_meta'];
     145
     146            if(!isset($posted_term_meta['auto_display_banner']))
     147                $posted_term_meta['auto_display_banner'] = 'off';
     148
     149            $cat_keys = array_keys( $posted_term_meta ); 
     150
     151            foreach ( $cat_keys as $key ){ 
     152                if ( isset( $posted_term_meta[$key] ) ){ 
     153                    $term_meta[$key] = $posted_term_meta[$key]; 
    127154                } 
    128155            } 
     
    133160   
    134161    // Retreives and print the category banner
    135     public function wcb_show_category_banner() {
     162    public function wcb_show_category_banner( $only_for_categories = true) {
    136163        global $woocommerce;
    137164        global $wp_query;
    138        
     165
    139166        // Make sure this is a product category page
    140         if ( is_product_category() ) {
    141            
     167        if ( is_product_category() || !$only_for_categories ) {
    142168            $cat_id = $wp_query->queried_object->term_id;
    143             $term_options = get_option( "taxonomy_term_$cat_id" );
    144            
    145             // Ge the banner image id
    146             if ( $term_options['banner_url_id'] != '' )
    147                 $url = wp_get_attachment_url( $term_options['banner_url_id'] );
    148 
    149             // Exit if the image url doesn't exist
    150             if ( !isset( $url ) or $url == false )
    151                 return;
    152 
    153             // Get the banner link if it exists
    154             if ( $term_options['banner_link'] != '' )
    155                 $link = $term_options['banner_link'];
    156 
    157             // Print Output
    158             if ( isset( $link ) )
    159                 echo "<a href='" . $link . "'>";
    160        
    161             if ( $url != false )
    162                 echo "<img src='" . $url . "' class='category_banner_image' />";
    163        
    164             if ( isset( $link ) )
    165                 echo "</a>";
     169
     170            $term_options = get_option( "taxonomy_term_$cat_id" );
     171
     172            if((isset($term_options['auto_display_banner']) && $term_options['auto_display_banner'] == 'on') || !isset($term_options['auto_display_banner'])) {
     173                // Get the banner image id
     174                if ( $term_options['banner_url_id'] != '' )
     175                    $url = wp_get_attachment_url( $term_options['banner_url_id'] );
     176
     177                // Exit if the image url doesn't exist
     178                if ( !isset( $url ) or $url == false )
     179                    return;
     180
     181                // Get the banner link if it exists
     182                if ( $term_options['banner_link'] != '' )
     183                    $link = $term_options['banner_link'];
     184
     185                // Print Output
     186                if ( isset( $link ) )
     187                    echo "<a href='" . $link . "'>";
     188           
     189                if ( $url != false )
     190                    echo "<img src='" . $url . "' class='category_banner_image' />";
     191           
     192                if ( isset( $link ) )
     193                    echo "</a>";
     194
     195            }
    166196        }
    167     } 
     197    }
    168198}
    169199
    170200endif;
    171201
    172 new WCB_Category_Banner();
     202$WCB_Category_Banner = new WCB_Category_Banner();
     203
     204//Shortcode function for displaying banner.
     205function wcb_show_category_banner() {
     206    global $WCB_Category_Banner;
     207    $WCB_Category_Banner->wcb_show_category_banner( false ); //disable the only show for category tag.
     208}
Note: See TracChangeset for help on using the changeset viewer.