• Resolved Chrissy

    (@paperkawaii)


    Hi I love your plugin!

    I have got it doing what I want, except how to add a class to categories that are parent categories. Or a class for child categories.

    This is what I have so far.. please ignore the bad formatting…

    This code shows all my categories in hierarchal order:

    <?php
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array(
    	'taxonomy' => 'category',
    		'term_args'    => array(
    			'orderby'      => 'id',
    			'order'        => 'ASC',
    			'hierarchical' => 1,
    		),
    	) );
    if ( ! empty( $terms ) ) {
    
    	foreach( (array) $terms as $term ) {
    		print "\n" . '<div class="postbox" id=" ' . esc_html( $term->name ) . ' ">';
    		print "\n\t" . '<h1 style=" margin-top: 10px; " class="entry-title"><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . esc_html( $term->name ) . '</a></h1>';
    		print "\n\t" . '<div class="entry-meta"><span class="entry-date">There are ' . esc_html( $term->count ) . ' posts in this category</span></div>';
    		print "\n\t" . '<div class="home-thumb"><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'home-thumb' ) . '</a></div>';		
    
    		print "\n\t" . '<div style="margin: 0px 0 0 0; z-index: 99999; position: relative; height: 50px; overflow: hidden; padding: 0 10px">' . esc_html( $term->description ) . '</div>';
    		print "\n" . '<div class="readmore" style="position: relative; height: 52px; display: block; padding: 10px 0;"><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '"> View All ' . esc_html( $term->name ) . '</a></div>
    
                    ';
    		print "\n" . '<div class="clearfix"></div></div>';
    
    	}
    }
    ?>

    It is this line

    print "\n" . '<div class="postbox" id=" ' . esc_html( $term->name ) . ' ">';

    that I would like to add the class ‘parent’ to if it is one.`

    Hope to hear from you, or anyone else who can help!

    https://www.ads-software.com/plugins/taxonomy-images/

Viewing 1 replies (of 1 total)
  • Thread Starter Chrissy

    (@paperkawaii)

    hah.. figured it out.

    so now I have

    print "\n" . '<div class="postbox" id="post' . esc_html( $term->parent ) . '">';

    so the id for parents is ‘0’

    so now I can use css like

    div#post0.postbox{
    	background: red
    }

    maybe that helps someone..

Viewing 1 replies (of 1 total)
  • The topic ‘How can I add a class if category has parent’ is closed to new replies.