Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 96024

wirefury on "Using Custom Taxonomies As A Class Selector"

$
0
0

Hi,
I'm creating a new search function for our site.

Here is an example of the standard HTML I would use in the lists. Pay particular attention to the

  • class selectors:
    <li class="col-md-2 panel panel-default mix beige granite" data-name="Picasso"><img src="<?php bloginfo('url'); ?>/wp-content/uploads/granite/Picasso.jpg" class="img-responsive"><p>Picasso</p></li>
            <li class="col-md-2 panel panel-default mix black granite" data-name="Earth Glitter"><img src="<?php bloginfo('url'); ?>/wp-content/uploads/granite/EarthGlitter.jpg" class="img-responsive"><p>Earth Glitter</p></li>
            <li class="col-md-2 panel panel-default mix black granite" data-name="Blue Sapphire"><img src="<?php bloginfo('url'); ?>/wp-content/uploads/newslabs/granite/BlueSapphire.jpg" class="img-responsive"><p>Blue Sapphire</p></li>

    My goal is to use the custom post types and their respective custom taxonomies I've created in a loop.
    For example:
    Color:
    Brown
    Yellow
    Gold
    Green

    Stone Type:
    Marble
    Granite

    Here's the loop I wrote:

    <ul id="Grid" class="just grid">
    <?php
    query_posts( 'post_type=material');
    if (have_posts()) :
    	while (have_posts()) : the_post();
    ?>
    
    	<li class="col-md-2 panel panel-default <?php wp_get_post_terms($post->ID, 'color', array("fields" => "all")); ?> mix" data-name="<?php the_title();?>"></li><img src="<?php wp_get_attachment_image_url('$id'); ?>" class="img-responsive"><p><?php the_title();?></p></li>
    <li class="gap"></li>
    <?php endwhile;?>
    
    </ul>
    <?php else:?>
    <h2 class="center">Not Found</h2>
    <p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
    <?php endif; ?>

    My issue is that I can not seem to get the custom taxonomies of each custom post to get added into the class of the

  • tags. I've tried all different combinations of get_terms, get_taxonomy, get_post_terms, etc. but nothing seems to just give me the taxonomies of the post.
    I have been able to get the links of the individual posts but not just the vanilla taxonomies.

    I've also gone down the post_class by adding the taxonomies to the available post classes but that gave me more classes than I needed and broke the loop.

    Thanks in advance for anyone who can help or even point me in the right direction.

    WP4LYFE!!! Amiright?


  • Viewing all articles
    Browse latest Browse all 96024

    Trending Articles