• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Genesis
    • WooCommerce
    • WordPress
  • Premium
  • Blog
  • About
    • Tools I Use
  • Contact
  • Login
Home » taxonomy

taxonomy

Echo custom post type taxonomy name and slug with function

2021-01-07 by Gabor Leave a Comment

Filed Under: WordPress Tagged With: CPT, name, slug, taxonomy

How do I list Custom Post Type’s Taxonomies

2020-11-26 by Gabor Leave a Comment

Filed Under: WordPress Tagged With: custom post type, taxonomy

Display title of current Custom Post Type’s taxonomy

2020-05-15 by Gabor Leave a Comment

    $terms = get_the_terms( $post->ID, 'YOUR_TAXONOMY' ); 
    foreach($terms as $term) { 
        echo $term->name; 
        echo $term->slug; 
    } 

Filed Under: WordPress Tagged With: category, custom post type, slug, taxonomy

Echo something conditionally on the single page of specific Custom Post Type Taxonomy

2020-02-29 by Gabor Leave a Comment

// ==================================================================
// SINGLE PAGE OF SPECIFIC CPT TAXONOMY
// ==================================================================
function single_page_of_specific_cpt_taxonomy(){
    global $post; 
    if(is_singular('YOUR_CPT')){
       foreach (get_the_terms(get_the_ID(), 'YOUR_TAXONOMY') as $cat) {
           //echo $cat->slug;
           if($cat->slug === 'YOUR_TERM'){
               echo 'YEAHHH!!!!';
           }
        }
    }
}
add_action('genesis_entry_content', 'single_page_of_specific_cpt_taxonomy');

Filed Under: Genesis, WordPress Tagged With: conditional, taxonomy

Full-width hero image on category / tag / taxonomy archive pages in Genesis

2019-02-16 by Gabor Leave a Comment

Below is a variation of the earlier linked tutorial which will work not only on category archives (Ex.: example.com/category/category-1) but also on tag archives (Ex.: example.com/tag/headlines) and any other custom taxonomy term archive pages (Ex.: example.com/portfolio_category/featured).

Step 1

Install and activate WP Term Images plugin.

Step 2

Edit category / tag / taxonomy archive pages and set your desired images.

Step 3

Add the following in child theme’s functions.php:

// Register custom image size for hero images on category / tag / taxonomy archive pages.
add_image_size( 'category-image', 1600, 400, true );

add_action( 'genesis_after_header', 'sk_taxonomy_term_hero_image' );
/**
 * Display hero image below header on category / tag / taxonomy archive pages.
 */
function sk_taxonomy_term_hero_image() {
    global $wp_query;

    // if we are not on a category archive or tag archive or a taxonomy archive, abort.
    if ( ! is_category() && ! is_tag() && ! is_tax() ) {
        return;
    }

    // get and store the object of current taxonomy term or category or tag.
    $term = is_tax() ? get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ) : $wp_query->get_queried_object();

    if ( ! $term ) {
        return;
    }

    // image id is stored as term meta.
    $image_id = get_term_meta( $term->term_id, 'image', true );

    // image data stored in array, second argument is which image size to retrieve.
    $image_data = wp_get_attachment_image_src( $image_id, 'category-image' );

    // image url is the first item in the array (aka 0).
    $image = $image_data[0];

    // if there's no image for this category, abort.
    if ( empty( $image ) ) {
        return;
    }

    printf( '<figure class="term-image"><img src="%s" alt="%s" /></figure>', $image, single_cat_title( '', false ) );
}

Step 4

Add the following in child theme’s style.css:

.category-image img {
    vertical-align: top;
    width: 100%;
}

References:

How to display taxonomy term image below archive intro text in Genesis

single_cat_title()

Filed Under: Genesis Tagged With: category, hero image, taxonomy, terms

Primary Sidebar

  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
WP Rocket - WordPress Caching Plugin
UpdraftPlus Premium

Disclosure: Some of the links in this site are affiliate links. I will be paid a commission if you use this link to make a purchase.

  • Privacy Policy
  • Flames Design
© 2021 WP Flames - All Right Reserved