Skip to content

Instantly share code, notes, and snippets.

@croosen
croosen / content-product.php
Last active June 8, 2017 15:36
WordPress - WooCommerce - show attributes in loop
// Get the attibutes
$attributes = $product->get_attributes();
// Loop and display the value
// var_dump $attributes to see what you can output
foreach ($attributes as $attribute) {
echo $attribute['value'];
}
@croosen
croosen / wc-template-functions.php
Last active August 29, 2015 14:06
WooCommerce - Show all subcategories in product category / archive pages - even when empty
$args = apply_filters( 'woocommerce_product_subcategories_args', array(
'parent' => $parent_id,
'menu_order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'taxonomy' => 'product_cat',
'pad_counts' => 1
) );
// Update: Use this in your functions.php:
@croosen
croosen / content-product.php
Last active February 5, 2018 14:42
WooCommerce - Display custom attributes on shop page - the official way ;-)
// Paste this in your file, somewhere in the loop, around the h3
<?php echo $product->sku; ?> <?php echo $product->omschrijving; ?> <?php the_title(); ?>
<?php
// Get the attributes
$attributes = $product->get_attributes();
// Start the loop
foreach ( $attributes as $attribute ) : ?>
<?php
@croosen
croosen / pages_custom_post_cat.php
Last active August 29, 2015 14:06
WordPress - Show categories of custom post type on template file
<?php
$taxonomy = 'your_taxonomy_name';
$terms = get_terms($taxonomy); // Get all terms of a taxonomy
if ( $terms && !is_wp_error( $terms ) ) : ?>
<ul>
<?php foreach ( $terms as $term ) { ?>
<li><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li>
<?php } ?>
</ul>
@croosen
croosen / single-knowledgebase.php
Last active August 29, 2015 14:06
WordPress - Show taxonomies / categories of custom post type
<?php
$customPostTaxonomies = get_object_taxonomies('foo');
if(count($customPostTaxonomies) > 0)
{
foreach($customPostTaxonomies as $tax)
{
$args = array(
'orderby' => 'name',
'show_count' => 0,
@croosen
croosen / single-knowledgebase.php
Last active August 29, 2015 14:06
WordPress - Show categories that belong to the current custom post
<?php
$taxonomy = 'foo_cat'; // Your category
$terms = get_the_terms($post->ID, $taxonomy ); // Get data for post ID
if ( $terms && !is_wp_error( $terms ) ) :
?>
<?php foreach ( $terms as $term ) { ?>
<li><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li>
<?php } ?>
@croosen
croosen / gist:784f08792d93c449ae48
Last active August 29, 2015 14:09
Vertical align with CSS / including Sass mixin
/* Vertical align
* Use this mixin or placeholder to vertical align elements
* @corinneroosen
*/
// Mixin
@mixin vertical-align {
position: relative; // Sometimes you need to try "absolute" here
top: 50%;
-webkit-transform: translateY(-50%);
@croosen
croosen / gist:ae6e046ed5b4c1940e10
Created December 6, 2014 19:47
Fancy "I Miss You" page title
// Fancy "I Miss You" page title
var missingYou = function() {
// Set blur/focus to check if browsertab is active
$(window).on('blur', function() {
document.title = "I miss you ♥";
}).on('focus', function() {
document.title = "Welcome back!";
});
};
@croosen
croosen / gist:27b4502153499581e3cf
Created December 28, 2014 18:35
Vertical align
.parent-element {
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
@croosen
croosen / group-product-categories.php
Created December 9, 2015 13:18
Groups WP taxonomies by parent
foreach( get_terms( 'product-categories', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) {
// display top level term name
echo $parent_term->name;
foreach( get_terms( 'product-categories', array( 'hide_empty' => false, 'parent' => $parent_term->term_id ) ) as $child_term ) {
// display name of all childs of the parent term
echo $child_term->name;
}
}