• Hi
    I am attempting to display a number of custom taxonomies as I did with categories but the syntax is confusing me (Im not a php wizard ?? ).
    This code worked well with the categorys get_category b ut due to admin usability id like to switch over to custom posts type with custom taxonomy.
    I have used a plugin to create my custom post types and generate the custom taxonomies, it is calling them in the template I have an issue with.

    Here is the previous code that worked like a charm with get_category, I have changed the top bit, I’ve been giving this a good go! I realise get_category needs to change to get_taxonomies, but after that I get stuck…

    <?php
    
    					$args=array(
    
    						'taxonomy' => 'product_categories',
    
    						'orderby' => 'name',
    
    						'order' => 'ASC'						
    
    						);
    
    					$categories=get_categories($args);
    
    						foreach($categories as $cat) { 
    
    							echo '<div class="col310">';
    
    							echo '<a href="' . get_term_link( $cat->term_id ) . '" title="' . sprintf( __( "View all products in %s" ), $cat->name ) . '" ' . '><img src="' . z_taxonomy_image_url($cat->term_id).'"' . ' />';
    
    							echo '<h3><a href="' . get_term_link( $cat->term_id ) . '" title="' . sprintf( __( "View all products in %s" ), $cat->name ) . '" ' . '>' . $cat->name.'</a></h3> ';
    
    							echo '<p>'. $cat->description . '</p>';
    
    							echo '<a href="' . get_term_link( $cat->term_id ) . '" title="' . sprintf( __( "View all products in %s" ), $cat->name ) . '" class="link"' . '><img src="' . get_template_directory_uri().'/images/cat-arrow.png" width="17" height="17" alt="View"' . ' /></a>';
    
    							echo '</div>'; } 
    
    					?>

    Any help is much appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter zerodotnine

    (@zerodotnine)

    Hi, does anyone have any advice on this, otherwise I might just create a new custom section for the news articles and leave the products in the posts area as the code seems to work for that. Is that a bad idea?

    Thread Starter zerodotnine

    (@zerodotnine)

    Thank you for the reply ??

    So instead of
    $categories=get_categories($args);
    I would use
    $categories=get_terms( $taxonomies, $args );

    The following items use get_term_link so these should then work?
    get_term_link( $cat->term_id )

    Hmmm. No!

    Please, see this example

    $terms = get_terms('species');
    echo '<ul>';
    foreach ($terms as $term) {
        echo '<li><a href="'.get_term_link($term->slug, 'species').'">'.$term->name.'</a></li>';
    }
    echo '</ul>';
    Thread Starter zerodotnine

    (@zerodotnine)

    ok, that makes a lot more sense, I’ll give that a go, thanks for the advice, this is new to me and I really appreciate the help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Post Taxonomies’ is closed to new replies.