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 4 months, 1 week ago by Columbus.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Daniel Llewellyn

    (@diddledan)

    Hi,

    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:

    ...
    <?php
    while( $a_z_query->have_items() ) :
        $a_z_query->the_item();
        $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(); ?>
        </a>
    </li>
        <?php endwhile; ?>
    ...
    • This reply was modified 3 months, 4 weeks ago by Daniel Llewellyn. Reason: fix mistaken use of get_the_terms() - better to use has_term()

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.