- This topic has 29 replies, 3 voices, and was last updated 4 years, 7 months ago by David.
-
AuthorPosts
-
August 23, 2019 at 11:06 am #991785webcréateur
The snippet did not Work … ):
August 23, 2019 at 1:27 pm #991863DavidStaffCustomer SupportSo looks like that method won’t work, the_title filter we are using cannot be specified where and where not to display. Hence the issue we are having as a lot of dynamic content use the_title for displaying content. Which is what WPSP and the sidebar links are doing.
Can you remove the second snippet and the CSS. We can keep the Custom Taxonomy and ill proivde some CSS to display the Badges. Let me know.
Can you also provide a list of the Badge names you’re going to be using.
August 24, 2019 at 1:20 am #992070webcréateurHi there,
the second snippet and the CSS is removed.
At the beginning we will start with 5 Badges:
- Premium
- Positions
- Interview
- Letters
- Comment
August 24, 2019 at 5:06 am #992179DavidStaffCustomer SupportSo this CSS is for the WPSP and Archives:
/* Default set-up of badges */ body:not(.single) article[class*="post-badges"] h2:after { color: #fff; margin-left: 0.5em; padding: 6px 4px; font-size: 12px; border-radius: 2px; vertical-align: top; } /* Individual rules for each badge - duplicate and change the slug in .post-badges-slug */ body:not(.single) .post-badges-premium h2:after{ content: 'Premium'; background-color: #f00; }
Slight issue with the Single Post. The H1 is within the Header Element which means it is placed before the article container that carries the
post-badges-slug
class so we can’t target it using this method. Let us know if the above works and is practical first and then we can look at some code for the single post.August 24, 2019 at 5:32 am #992193webcréateurTHANK YOU!
This works fine on front page content area and seems to be practical. but this time the badge is not shown in sidebar widget area, also displayed with WP SHOW POSTS and WP recent Posts…
August 24, 2019 at 5:34 am #992194DavidStaffCustomer SupportUnfortunately sidebar widgets don’t carry taxonomy classes so can’t be styled. Hence the original crazy idea to bend the_title() filter to our will ( and failed lol )
The simplest solution is to use one a WPSP list for your sidebar lists.August 24, 2019 at 5:47 am #992202webcréateurI don’t know what to do anymore.
In theory our requirement is to put a simple badge behind certain posts.
WP Show Posts makes this difficult somehow, or…?August 24, 2019 at 7:28 am #992252webcréateurHow can I show Badge on single posts?
August 24, 2019 at 3:52 pm #992572TomLead DeveloperLead DeveloperTo get this to work on single posts, we would need to first add the category classes to the
<body>
element.Can you add this function and let us know?:
add_filter( 'body_class', function( $classes ) { if ( is_single() ) { global $post; foreach( ( get_the_category( $post->ID ) ) as $category ) { $classes[] = 'cat-' . $category->category_nicename; } } return $classes; } );
August 24, 2019 at 9:06 pm #992647webcréateurThank you. I just added the function …
August 25, 2019 at 3:19 am #992737DavidStaffCustomer SupportSorry the code that Tom provided only applies to the standard Categories. Can you replace it with this function:
function badge_taxonomy_in_body_class( $classes ){ if( is_singular() ) { global $post; $custom_terms = get_the_terms($post->ID, 'post-badges'); if ($custom_terms) { foreach ($custom_terms as $custom_term) { $classes[] = 'badge-' . $custom_term->slug; } } } return $classes; } add_filter( 'body_class', 'badge_taxonomy_in_body_class' );
Once in i can test and provide you with the complete CSS to add the badges
August 25, 2019 at 3:31 am #992744webcréateurThank you … just replaced the function.
August 25, 2019 at 3:51 am #992746DavidStaffCustomer SupportRight made one tweak to this snippet:
the change is
$classes[] = 'cat-' . $custom_term->slug;
becomes$classes[] = 'badge-' . $custom_term->slug;
Once thats done update your CSS to include the H1 styling – so it now looks like this:
body:not(.single) article[class*="post-badges"] h2:after, body[class*="badge-"] h1:after { color: #fff !important; margin-left: .5em; padding: 2px 4px; font-size: 12px; border-radius: 0; vertical-align: top } body:not(.single) .post-badges-premium h2:after, .badge-premium h1:after { content: 'Premium'; background-color: red }
August 25, 2019 at 5:23 am #992804webcréateurDavid, thank you for your patience with me.
With this solution I think we can work. 🙂
I marked this support topic as resolved.
But if you can think of anything else regarding the badges in the widget “Recent Post” I would be grateful.
August 25, 2019 at 5:38 am #992812DavidStaffCustomer SupportAwesome – so glad we could be of help.
As i said with the Related Posts widget there is no category tag for us to target.
If you create a new WPSP list, then you can set that to display latest posts and add that as a sidebar widget. Then you’re badges should display. -
AuthorPosts
- You must be logged in to reply to this topic.