• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Assigns each category link color from post meta.

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Assigns each category link color from post meta.

This topic is: not resolved

Tagged: get_the_category_list, nth child, post meta

  • This topic has 8 replies, 2 voices, and was last updated 9 years, 2 months ago by Brad Dalton.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • May 9, 2016 at 9:27 pm #185327
    paula1
    Member

    Hi 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 #185328
    Brad Dalton
    Participant

    You want a different color for each category link? How many categories?


    Tutorials for StudioPress Themes.

    May 9, 2016 at 9:48 pm #185329
    paula1
    Member

    Thanks 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 #185331
    Brad Dalton
    Participant

    Try https://css-tricks.com/how-nth-child-works/


    Tutorials for StudioPress Themes.

    May 9, 2016 at 11:03 pm #185332
    paula1
    Member

    That'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 #185333
    paula1
    Member

    Would 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 #185334
    Brad Dalton
    Participant

    Works like this:

    Screen Shot 2016 05 10 at 12 31 30 PM


    Tutorials for StudioPress Themes.

    May 10, 2016 at 12:02 am #185335
    paula1
    Member

    Yes, 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 = Blue

    So, 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 #185336
    Brad Dalton
    Participant

    Not 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.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble