madeinthearcade
6/23/2017 - 10:22 AM

Display all custom taxonomies on archive page for custom post type

Display all custom taxonomies on archive page for custom post type

            <?php 
                while ( have_posts() ) {
                    the_post(); 
                    the_content();
                }

                $terms          = get_terms( 'product-categories' );

                echo '<div class="flex-container">';

                foreach ( $terms as $term ) {
                    $term_link = get_term_link( $term );
                    if ( is_wp_error( $term_link ) ) {
                        continue;
                    }
                    echo '<a href="' . esc_url( $term_link ) . '" class="flex-item">';

                    $categoryImage  = get_field( 'category_image', $term );
                        if ( $categoryImage ) {
                            echo '<img src="' . $categoryImage['url'] . '" alt="' . $term->name . '">';
                        }
                        else {
                            echo '<img src="' . get_template_directory_uri() . '/img/template/category-placeholder.png" alt="' . $term->name . '">';
                        }

                    echo '<div class="overlay"><div class="caption"><h3>' . $term->name . '<h3></div><span class="btn white-outline">Explore more</span></div></a>'; 
                }
                echo '</div>';
            ?>