Tagged: ,

Viewing 10 reply threads
  • Author
    Posts
    • #3188
      Jan Gruchow
      Member

      Hi
      i set up a custom post type “product” and a custom taxonomie “product-color”.

      Now i want to display the active colors on the single-product.php an link to the color-archive-page. It should be like tags an categories are linked on the standard posts on most templates.

      Can anyone tell me, what code i have to put into my theme?

      Thx
      Jan

    • #3189
      Steve
      Keymaster

      Welcome to the Piklist Community!

      I think you want to use wp_get_object_terms()

      The example on the codex page looks like it will do what you want.

      Let us know if this works for you.

    • #3190
      Jan Gruchow
      Member

      Hi

      perfekt, that was what i was looking for.

      For interested readers, here is the full snipped i use:

      $product_colors = wp_get_object_terms( $post->ID,  'product_color' );
      						if ( ! empty( $product_colors ) ) {
      							if ( ! is_wp_error( $product_colors ) ) {
      								echo '<ul>';
      									foreach( $product_colors as $term ) {
      										echo '<li><a href="' . get_term_link( $term->slug, 'product_color' ) . '">' . $term->name . '</a></li>'; 
      									}
      								echo '</ul>';
      							}
      						}
    • #3191
      Steve
      Keymaster

      Glad it worked for you! One of the best parts of Piklist is that, in most cases, you can use standard WordPress functions to work with your data.

    • #3192
      Jan Gruchow
      Member

      that’s true.

      since i’am not good in programming, it is hard for me to find the right things in the WP-codex-reference, especially if i don’t even know what to look for.

    • #3195
      Jan Gruchow
      Member

      I have one mor question: As i wrote in my example, i use
      <a href="' . get_term_link( $term->slug, 'product_color' ) . '">' . $term->name . '</a>
      to generate my links back to the archive. these links look like this:
      domain.com/?color=blue

      My problem ist, that i want to use the product-archive-template. The links should look like domain.com/products/?color=blue

      is there a easy way to change the links, so the custom-post-type-slug is added? I couldn’t find anything in the wp-codex.

    • #3198
      Steve
      Keymaster

      @jan– It looks like you left off a parameter when you registered the taxonomy. Try adding:

      ,'rewrite' => array( 
        'slug' => 'products' 
      )
      

      Look in piklist/add-ons/piklist-demos/piklist-demos.php for an example of how we registered the piklist_demo_type taxonomy.

    • #3284
      Jan Gruchow
      Member

      Hi

      i have set the rewrite slug. But this is for the singe-product-url, not?

      I have set:

      
      ,'has_archive' => 'products'
      		,'rewrite' => array(
      		  'slug' => 'product'
      		)
      

      That way, URLs like:
      domain.com/products/a-product-list
      domain.com/product/a-single-product
      and it works fine.

      I only dont know, how i can get the get_term_link-function to link to the specific product-archive and not just the generic archive…
      The Link:
      domain.com/?color=blue
      is also displaying the right product, but i uses the default archive-template. I that to use my specific archive-product-template so i need them to link to domain.com/PRODUCTS/?color=blue

    • #3287
      Steve
      Keymaster

      @Jan– Taxonomies also use the rewrite parameter.

    • #3289
      Jan Gruchow
      Member

      Thanks for the hint, but i think it’s still not the right solution for me.

      i have set the rewrite for the taxonomies to “false”, because i want my categories with URL-Parameters.
      If i use the the slug and/or with-front for the rewrite, i automatically active the pretty links (what i don’t want). And there is also no way to set the “/products/”.

      Or am i missing something?

    • #3297
      Steve
      Keymaster

      @jan– I’m sorry… I think I’m confused. Please explain in detail what you are trying to accomplish. We are happy to help.

Viewing 10 reply threads
  • You must be logged in to reply to this topic.