Support » Plugin: A-Z Listing » Add Taxonomy title to index name

  • Resolved thefatgamer

    (@thefatgamer)


    Hi Daniel,

    Firstly, fantastic plugin!

    I operate a gaming review website for retro-games – as you can imagine, there are game names that are the same across multiple platforms. Therefore, when all games are listed in the master index, they appear twice (which is correct) but the visitor doesn’t know what platform (aka category) the game is in until they click on the post name and visit the game page.

    I’m thinking of creating individual game-indexes for each platform using this shortcode: [a-z-listing post-type=”post” taxonomy=”category” terms=”atari-2600″] to get around this, however my question is it possible to include the category (or even tag) name in the name of the post?

    So the index might read:

    Castlevania [NES]
    Castlevania [Nintendo 64]

    Many thanks!

    Pete

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Daniel Llewellyn

    (@diddledan)

    Yes, this can be achieved, but it might break because of resource limits on your server. It is a heavy operation and the larger the listing the more resource intensive the process.

    With that caveat aside, the way to do it is to copy the template from the plugin folder at templates/a-z-listing.php into your theme and adjust it slightly.

    On line 37 (in version 2.1.0) you will need to insert a new line after the opening <?php tag with:

    $post = $a_z_query->get_the_item_object( 'I understand the issues!' );
    

    The text I understand the issues! must be exactly that for the plugin to accept that you really have read my warning about it potentially being slow or breaking due to resource constraints, or both.

    Once you have the $post you can edit line 58 (again in version 2.1.0) to append the following on a new line:

    <?php
    $terms = get_the_terms( $post, 'category' );
    if ( $terms ) :
        echo '[' . esc_html( implode( ', ', $terms ) ) . ']';
    endif;
    ?>

    Thanks Daniel,

    I understand about the server load – I’ll evaluate the impact and that will dictate if I use it or not.

    I’ll have a go at implementing – I’ll mark off as resolved for now.

    Pete

    Hi Daniel,

    Your plugin is really good but i have some more things to be displayed which involved displaying the name of the category that i have mentioned in wp_terms.
    I am trying to get the name field of wp_term and display it with the title.

    How do I try to get this name in the array

    Plugin Author Daniel Llewellyn

    (@diddledan)

    Sorry, my code above was incorrect. To show the term names you need to run the array through a map first:

    echo '[' . esc_html(
        implode(
            ', ',
            array_map(
                $terms,
                function( $term ) {
                    return $term->name;
                }
            )
        )
    ) . ']';
    • This reply was modified 2 months, 1 week ago by  Daniel Llewellyn. Reason: fix new code
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.