- This topic has 10 replies, 2 voices, and was last updated 7 years ago by
Steve.
-
AuthorPosts
-
-
January 17, 2015 at 5:58 pm #3188
Jan GruchowMemberHi
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 -
January 17, 2015 at 8:06 pm #3189
SteveKeymasterWelcome 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.
-
January 18, 2015 at 7:18 am #3190
Jan GruchowMemberHi
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>'; } } -
January 18, 2015 at 8:25 am #3191
SteveKeymasterGlad 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.
-
January 18, 2015 at 2:47 pm #3192
Jan GruchowMemberthat’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.
-
January 21, 2015 at 3:20 am #3195
Jan GruchowMemberI 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=blueMy 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.
-
January 21, 2015 at 3:21 pm #3198
SteveKeymaster@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_typetaxonomy. -
February 9, 2015 at 5:15 am #3284
Jan GruchowMemberHi
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 -
February 9, 2015 at 2:40 pm #3287
SteveKeymaster@Jan– Taxonomies also use the
rewriteparameter. -
February 9, 2015 at 3:32 pm #3289
Jan GruchowMemberThanks 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?
-
February 9, 2015 at 10:30 pm #3297
SteveKeymaster@jan– I’m sorry… I think I’m confused. Please explain in detail what you are trying to accomplish. We are happy to help.
-
-
AuthorPosts
- You must be logged in to reply to this topic.