WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Taxonomies (6 posts)

  1. zerodotnine
    Member
    Posted 1 year ago #

    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!

  2. zerodotnine
    Member
    Posted 1 year ago #

    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?

  3. LIMEXS
    Member
    Posted 1 year ago #

  4. zerodotnine
    Member
    Posted 1 year ago #

    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 )

  5. LIMEXS
    Member
    Posted 1 year ago #

    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>';
  6. zerodotnine
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic