Community Forums › Forums › Archived Forums › Design Tips and Tricks › Assigns each category link color from post meta.
Tagged: get_the_category_list, nth child, post meta
- This topic has 8 replies, 2 voices, and was last updated 9 years, 8 months ago by
Brad Dalton.
-
AuthorPosts
-
May 9, 2016 at 9:27 pm #185327
paula1
MemberHi there
Is it possible to assign each category link color form post meta (genesis_post_categories_shortcode)?
I notice that post meta comes from - genesis_post_categories_shortcode function from post.php.
function genesis_post_categories_shortcode( $atts ) { $defaults = array( 'sep' => ', ', 'before' => __( 'Filed Under: ', 'genesis' ), 'after' => '', ); $atts = shortcode_atts( $defaults, $atts, 'post_categories' ); $cats = get_the_category_list( trim( $atts['sep'] ) . ' ' ); //* Do nothing if no cats if ( ! $cats ) { return ''; } if ( genesis_html5() ) $output = sprintf( '<span %s>', genesis_attr( 'entry-categories' ) ) . $atts['before'] . $cats . $atts['after'] . '</span>'; else $output = '<span class="categories">' . $atts['before'] . $cats . $atts['after'] . '</span>'; return apply_filters( 'genesis_post_categories_shortcode', $output, $atts ); }May 9, 2016 at 9:44 pm #185328Brad Dalton
ParticipantYou want a different color for each category link? How many categories?
May 9, 2016 at 9:48 pm #185329paula1
MemberThanks for quick reply. I do appreciate it braddalton.
Yes. I really want to display different color for each category link at post meta.
I've 4-5 categories in my blog.
May 9, 2016 at 10:26 pm #185331Brad Dalton
ParticipantMay 9, 2016 at 11:03 pm #185332paula1
MemberThat's really neat solution. I did try and it works. Fantastic.
But, sadly, that won't help to assign specific color for each category link.
May 9, 2016 at 11:15 pm #185333paula1
MemberWould it be possible to add category slug in $output span?
$output = sprintf( '<span %s>', genesis_attr( 'entry-categories' ) ) . $atts['before'] . $cats . $atts['after'] . '</span>';May 9, 2016 at 11:33 pm #185334Brad Dalton
ParticipantMay 10, 2016 at 12:02 am #185335paula1
MemberYes, Brad. It works like in your reply. nth-child selector handles well to add different colors for category links.
As an example above -
Category 2 = Orange
Category 5 = Blue
...
...
... etc.But if the post is under category 1 and category 3, those two category links will go with same colors -
Category 1 = Orange
Category 3 = BlueSo, nth-child selector - it doesn't help to assign specific color for each category link.
But, I really like your solution. Just using CSS to achieve it.
May 10, 2016 at 12:06 am #185336Brad Dalton
ParticipantNot based on my solution.
Styles each link differently on all single posts and archive types regardless of how many categories each post is assigned to.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.
