- This topic has 14 replies, 4 voices, and was last updated 2 years, 8 months ago by Elvin.
-
AuthorPosts
-
July 31, 2021 at 2:59 pm #1878819Susanne
Hi there,
I have built a site using the latest GP and GP premium plugin and a child theme.
I have a custom post Type “portfolio” and have created 3 categories for the CPT, and a filter menu, which display the 3 categories correctly.
However, I cannot get the tags to show either in the archive view or the single view. They show in the blog posts. They are correctly assigned to the portfolio posts ( I am using Portfolio post type plugin).I have a single-portfolio and a content-portfolio.php in my child theme but no modifications so far.
Do I have to add something to the functions? I have made it work a couple of years ago in an older version of GP, but now things are different and I am lost.
The only relevant code in my functions is this and that works fineadd_filter('generate_blog_masonry','generate_blog_disable_blog_masonry'); function generate_blog_disable_blog_masonry() { // If we're on the posts page, disable masonry if ( is_home() || is_page() || is_single() ) return 'false'; // Otherwise, enable it return 'true'; }
What do I have to do? Thanks for your help
August 1, 2021 at 5:12 am #1879140DavidStaffCustomer SupportHi there,
to enable the post meta on your CPT you can use this PHP Snippet:
add_filter( 'generate_entry_meta_post_types', function( $types ) { $types[] = 'portfolio'; return $types; } );
And then this snippet to tell it what you want to display in the Meta:
add_filter( 'generate_header_entry_meta_items', function( $items ) { if ( 'portfolio' === get_post_type() ) { $items = array( 'date', ); } return $items; } );
More info on that filter here:
https://docs.generatepress.com/article/generate_header_entry_meta_items/
Or alternatively you can create your own Content Templates or Post Meta templates in the block editor:
https://docs.generatepress.com/article/block-element-content-template/
https://docs.generatepress.com/article/block-element-post-meta-template/
August 1, 2021 at 11:49 am #1879702SusanneHi David,
Thank you for your quick reply. I added these filters to my functions.php and got no results. I assume they go in the functions. Funny enough though, the date will show, which is the only one I don’t want, but not the tags or categories.
Should I write these into the content-portfolio.php file instead of the functions?
On inspection of the archive page in Firefox, theshows up but has no content. I am sure I did something wrong, but I cannot figure out what it is. I am developing on MAMP.
Any other ideas?August 1, 2021 at 11:59 am #1879709LeoStaffCustomer SupportDavid’s function above only includes date which is why only the date is showing.
Have you checked out the documentation he linked which shows you the rest of the items so you can tweak the code?
https://docs.generatepress.com/article/generate_header_entry_meta_items/August 1, 2021 at 12:44 pm #1879734SusanneHi Leo,
Thanks for your reply,
Yes I am aware of that and I modified the function to readadd_filter( 'generate_header_entry_meta_items', function() { return array( 'date', 'tags', 'categories', ); } );
and the date shows but not categories or tags
so something is not right.
August 1, 2021 at 1:00 pm #1879750SusanneI added
add_action( 'generate_post_meta_items', function( $item ) { if ( 'portfolio-tags' === $item ) { echo 'tags:'; } } );
And the word ‘tags’ shows under the archive item, but not the tags themselves.They are portfolio tags, not regular tags
so I added
add_filter( 'generate_header_entry_meta_items', function() { $items[] = 'portfolio-tags'; return $items; } );
no tags are showing. But the nav displays the categories correctly, so they are identified, but not shown
August 1, 2021 at 10:19 pm #1879998ElvinStaffCustomer SupportIf the CPT is using the default
post_tag
, thetag
ongenerate_header_entry_meta_items
should be enough. But this won’t work if theportfolio-tags
is a custom taxonomy.Is the taxonomy of
portfolio-tags
a custom taxonomy? If yes, you’ll have to tellgenerate_post_meta_items
whatportfolio-tags
$item does so it does something when you call it on thegenerate_header_entry_meta_items
filter.Example: Say you have a taxonomy
portfolio_tags
, you’ll have to do something like this.add_filter( 'generate_entry_meta_post_types', function( $types ) { $types[] = 'portfolio'; return $types; } ); add_action( 'generate_post_meta_items', function( $item ) { if ( 'portfolio-tags' === $item ) { echo get_the_term_list( get_the_ID(), 'portfolio_tags', '', ', ' ); } } ); add_filter( 'generate_header_entry_meta_items', function() { return array( 'date', 'tags', 'categories', 'portfolio-tags', ); } );
The first part of the snippet tells the theme to display meta on CPT
portfolio
.The second part (important), tells the theme to pull terms from the custom taxonomy
portfolio_tags
.The third part tells the theme to include the one we did on the second part on the render of the post meta. π
August 2, 2021 at 6:18 pm #1881332SusanneDear Elvin,
You are a genius, thank you soo much! I did have to modify the code a bit because my taxonomy was actually “portfolio_tag” not “portfolio_tags”, but once I did that it actually worked. Thank you so much for taking the time to explain in detail how it works, that was so incredibly helpful. Thank you David an Leo also.
Your grateful customer
SusanneAugust 2, 2021 at 7:04 pm #1881371ElvinStaffCustomer SupportYeah those ones are always tricky.
No problem. Glad to be of any help. π
August 2, 2021 at 7:08 pm #1881381SusanneOne follow-up question: If I want a to assign a style to this tag, lets say .portfolio-tag, how would I do that? A filter?
August 2, 2021 at 9:52 pm #1881512ElvinStaffCustomer SupportCan you link me to an example page containing a post item w/ this custom taxonomy? So I can check which class selector is generated. π
August 3, 2021 at 8:22 pm #1882937SusanneHi Elvin,
I am developing locally, so can’t link you to a post, but the tags are contained in the div class =”entry-meta”, and above that in the div class=”entry-header”. thats all. So the tags themselves don’t have an ID or a style. Hope that helps.August 3, 2021 at 9:11 pm #1882955ElvinStaffCustomer SupportAh in this case:
I see you seem familiar with the Google devtools (right-click + inspect).
You can check the
<article>
tag of the post. You on this tag, you’ll see that on the class selectors, there are taxonomy classes.You can see something like
category-[your-category-slug]
ortag-[your-tag-slug]
. You’ll likely seeportfolio-[your-portfolio-slug]
here as well. – https://share.getcloudapp.com/rRubqzD9You can use this as a selector to style its ancestor elements.
Example: Changing the h2 within the article for portfolio “Dogs” to color red.
article.portfolio-dogs h2 { color: red; }
August 4, 2021 at 5:20 am #1883320SusanneThanks for that tip Elvin.Yes I see those selectors, however they are specific to that post. What I want to do is to create a filter or an action to assign a class to every portfolio tag within entry-meta.
I think I solved the problem by creating a hook in Elements (yeah Elements!) like this
<h5><?php echo get_the_term_list( $post->ID, 'portfolio_tag', 'Tags: ', ', ', '' ); ?></h5>
Now I have the tags showing with an h5 and I can style the h5 in the portfolio archive. But thank you so much for all of the thinking!
August 4, 2021 at 7:39 pm #1884328ElvinStaffCustomer SupportAh yeah that can work as well. glad you got it sorted. π
-
AuthorPosts
- You must be logged in to reply to this topic.