Created
January 22, 2013 04:45
-
-
Save wpsmith/4592102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Outputs HTML markup for category image for WooCommerce. | |
* | |
* @param int $cat_id Category ID. | |
* @param string $size Image size. | |
* @param array $attr Image attributes. | |
* @return string $orderby Modified orderby SQL string. | |
*/ | |
function wps_category_image( $cat_id, $size, $attr = array() ) { | |
// get the thumbnail id user the term_id | |
$thumbnail_id = get_woocommerce_term_meta( $cat_id, 'thumbnail_id', true ); | |
// get the image URL | |
$image = wp_get_attachment_url( $thumbnail_id ); | |
// print the IMG HTML | |
echo wp_get_attachment_image( $thumbnail_id, $size, false, $attr ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'get_terms_orderby', 'wps_get_terms_orderby', 10, 2 ); | |
/** | |
* Modifies the get_terms_orderby argument if orderby == include | |
* | |
* @param string $orderby Default orderby SQL string. | |
* @param array $args get_terms( $taxonomy, $args ) arg. | |
* @return string $orderby Modified orderby SQL string. | |
*/ | |
function wps_get_terms_orderby( $orderby, $args ) { | |
if ( isset( $args['orderby'] ) && 'include' == $args['orderby'] ) { | |
$include = implode(',', array_map( 'absint', $args['include'] )); | |
$orderby = "FIELD( t.term_id, $include )"; | |
} | |
return $orderby; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Output the homepage categories HTML Markup | |
* | |
* @uses wps_category_image() Outputs image HTML Markup | |
*/ | |
function wps_homepage_categories() { | |
$args = array( | |
'orderby' => 'include', | |
'order' => 'ASC', | |
'hide_empty' => false, | |
'include' => array( 28 /* Appearal */, 27 /* Accessories */, 30 /* Outerwear */, 29 /* Hiking */, 22 /* Grooming */, ), | |
'fields' => 'all', | |
'pad_counts' => false, | |
'd2c_home' => true, //optional | |
); | |
$product_cats = get_terms( 'product_cat', $args ); | |
foreach ( $product_cats as $cat ) { | |
wps_category_image( $cat->term_id, $size ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment