Support » Plugin: A-Z Listing » Hyperlink color per category

  • Hi, thanks for your great plugin! I’m trying to target different categories in one list with CSS. I would love to give each category its own hyperlink color. Would there be a function for this? I’m using Custom Post Types with ACF fields within a childtheme of Twenty-Sixteen. Thanks in advance!

    • This topic was modified 2 years, 1 month ago by Columbus.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Dani Llewellyn



    There isn’t a direct ability to do this provided by the plugin. If I’m understanding correctly, you are showing posts in your list and want each post title to be coloured by the post’s associated terms.

    You could try adding a template into your childtheme called a-z-listing.php copied from wp-content/plugins/a-z-listing/templates/a-z-listing.php. Within this file you’ll want to try using get_the_item_object() to load the $post variable inside the while( $a_z_query->have_items() ) loop. Then you can use has_term() from WordPress core to match against your list for colouring:

    while( $a_z_query->have_items() ) :
        $post = $a_z_query->get_the_item_object();
        if ( has_term( 'red-term-slug', 'taxonomy-slug', $post ) {
            print '<li class="red">';
        } elseif ( has_term( 'green-term-slug', 'taxonomy-slug', $post ) ) {
            print '<li class="green">';
        } else {
            print '<li class="boring colourless">';
        <a href="<?php $a_z_query->the_permalink(); ?>">
            <?php $a_z_query->the_title(); ?>
        <?php endwhile; ?>
    • This reply was modified 2 years, 1 month ago by Dani Llewellyn. Reason: fix mistaken use of get_the_terms() - better to use has_term()
    Thread Starter Columbus


    Thanks a lot!! I’ll give this a go 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hyperlink color per category’ is closed to new replies.