Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

this is a bit challenging for me: I am using the great Advanced Custom Field plugin on my site to create different color scheme to each of my taxonomy.

I created a field called taxonomy_color and echoed out the color like so:

<h4 style="color: <?php the_field('taxonomy_color', 'magazine_'. $tax_term->term_id); ?>;">Hello</h4>

* magazine_ is the name of my taxonomy.

This is fairly easy and it works perfectly, however, everything becomes more complex when I want to change my hover and active class too.

since changing the hover and/or active state requires a reference to the stylesheet I was thinking about creating a dynamic stylesheet called: style.php and trying to pass the custom field onto that stylesheet and using this method will allow me to control the hover and active states too.

this is the code I generated for my style.php:

<?php
    header("Content-type: text/css; charset: UTF-8");
?>
.slider-mag-template .bottom .nav li.activeSlide a,.slider-mag-template .bottom .nav li a:hover { color: <?php the_field('taxonomy_color', 'magazine_'. $tax_term->term_id); ?>;}

I can see in the site that the page is connected to my dynamic style.php but it doesn't read the field taxonomy_color from there.

can anyone suggest? even using a different method?

Thanks a lot

share|improve this question

1 Answer 1

I think the the_field function will only get you so far. You could use the WordPress get_post_meta function to get just the taxonomy name, and use that for the stylesheet.

<?php if ( get_post_meta(get_the_ID(), 'term_id', true) ) : // I think the custom field is called Term ID ?>

    <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/css/<?php echo( get_post_meta(get_the_ID(), 'term_id', true) ); ?>">

<?php endif; ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.