Changeset 1046236
- Timestamp:
- 12/16/2014 10:22:55 PM (11 years ago)
- Location:
- woocommerce-category-banner/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (4 diffs)
-
woocommerce-category-banner.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-category-banner/trunk/readme.txt
r907082 r1046236 4 4 Donate Link: http://wpbackoffice.com/plugins/woocommerce-category-banner/ 5 5 Requires at least: 2.3 6 Tested up to: 3.97 Stable tag: 1.1. 06 Tested up to: 4.0.1 7 Stable tag: 1.1.1 8 8 License: GPLv2 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 19 19 * No configuration needed, just install and start using 20 20 * 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. 21 22 * Support a link for each category / banner image 22 23 … … 28 29 4. That's it, your banner should now be displaying on your category archive page. 29 30 5. Remove image by deleting the url from the edit category page. 31 32 You can hide the automatic image placement by unchecking "Automatically insert banner above main content" 33 34 You 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. 30 35 31 36 [Plugin's Official Documentation and Support Page](http://wpbackoffice.com/plugins/woocommerce-category-banner/) … … 51 56 == Changelog == 52 57 58 = 1.1.1 = 59 * Adding Template tag for custom banner position for custom product category templates. 53 60 54 61 = 1.1.0 = -
woocommerce-category-banner/trunk/woocommerce-category-banner.php
r907086 r1046236 4 4 Plugin URI: http://www.wpbackoffice.com/plugins/woocommerce-category-banner/ 5 5 Description: 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. 06 Version: 1.1.1 7 7 Author: WP BackOffice 8 8 Author URI: http://www.wpbackoffice.com … … 16 16 17 17 public function __construct() { 18 18 19 global $woocommerce; 20 global $wp_query; 21 19 22 // Add Scripts and styles 20 23 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts_and_styles' ) ); … … 26 29 add_action( 'edited_product_cat', array( $this, 'wcb_product_cat_save_taxonomy_custom_fields'), 10, 2 ); 27 30 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) 29 32 add_action( 'woocommerce_before_main_content', array( $this, 'wcb_show_category_banner'), 30 ); 33 30 34 } 31 35 … … 77 81 else 78 82 $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 80 91 ?> 81 92 … … 110 121 </td> 111 122 </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> 112 134 113 135 <?php … … 120 142 $t_id = $term_id; 121 143 $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]; 127 154 } 128 155 } … … 133 160 134 161 // Retreives and print the category banner 135 public function wcb_show_category_banner( ) {162 public function wcb_show_category_banner( $only_for_categories = true) { 136 163 global $woocommerce; 137 164 global $wp_query; 138 165 139 166 // Make sure this is a product category page 140 if ( is_product_category() ) { 141 167 if ( is_product_category() || !$only_for_categories ) { 142 168 $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 } 166 196 } 167 } 197 } 168 198 } 169 199 170 200 endif; 171 201 172 new WCB_Category_Banner(); 202 $WCB_Category_Banner = new WCB_Category_Banner(); 203 204 //Shortcode function for displaying banner. 205 function 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.