- This topic has 22 replies, 2 voices, and was last updated 4 years ago by
David.
-
AuthorPosts
-
January 31, 2020 at 2:10 pm #1150857
Aldrin
Hi Dave…not sure what you mean by
display rules to the Product > All Products then you will see the Title and the Terms displayed on all products.
Can you give me an example ? Thank you
January 31, 2020 at 2:28 pm #1150872David
StaffCustomer Support1. Create a New Header Element.
2. Add this content:{{post_title}} {{post_terms.product_cat}}
3. Display Rules -> Product > All Products.
4. View a Single Product – you will see the Product Title followed by All the Categories that product belongs to.
What you CANNOT do is display the
{{post_terms.taxonomy}}
on an Archive Page.January 31, 2020 at 5:21 pm #1150937Aldrin
Gotcha…yes my main purpose was to do it on the archive pages..oh well. Thank you very much for the help. I’ll see if I can implement some custom coding via another route.
February 1, 2020 at 5:07 am #1151205David
StaffCustomer SupportHow would that be different to displaying the post title ?
Using your example:
1. for the
/product/Cars
archive – the {{post_title}} will display Cars.
2. the/product/Cars/BMW
archive -t he {{post_title}} will display BMW.January 25, 2021 at 11:19 pm #1633701Raul
I want to use them in my singel posts to show to respective category but it works only with elements->header but not with elements-hook ๐
And php is not working as hook like
$category = get_the_category(); $firstCategory = $category[0]->cat_name;
January 26, 2021 at 4:23 am #1633994David
StaffCustomer SupportHi there,
Template Tags only work within the Header element.
That code should work fine in a hook.
1. Make sure the code is wrapped in the correct tags eg.<?php $category = get_the_category(); $firstCategory = $category[0]->cat_name; echo $firstCategory; ?>
2. Check the Execute PHP option in the hook.
3. Make sure you’re using a Hook that is present on that template:January 26, 2021 at 6:18 am #1634123Raul
Hi, I used this here to getr the same like the header in the archive:
<header class="page-header"><h1 class="page-title"><?php $category = get_the_category(); $firstCategory = $category[0]->cat_name; echo $firstCategory; ?></h1></header>
Seems to be working ๐
Or with a link if someone need this
<header class="page-header"><h1 class="page-title"> <?php $category = get_the_category(); $first_category = $category[0]; echo sprintf( '<a href="%s">%s</a>', get_category_link( $first_category ), $first_category->name ); ?> </h1></header>
And for all categorys:
<header class="page-header"><h1 class="page-title"> <?php $categories = get_the_category(); $separator = ' >> '; $output = ''; if ( ! empty( $categories ) ) { foreach( $categories as $category ) { $output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</a>' . $separator; } echo trim( $output, $separator ); } ?> </h1></header>
January 26, 2021 at 7:26 am #1634402David
StaffCustomer SupportGlad to see you found the solution.
-
AuthorPosts
- You must be logged in to reply to this topic.