• Hi, I’ve got the plugin working and its great. I was wondering if its ppossible to show the post category in brackets after the post name. It will make more sense if you have a look at the link to the archive I have.
    something like this…
    artists name (year)
    where ‘artist name’ is the post title & ‘year’ is the category the post is in

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Dani Llewellyn

    (@diddledani)

    Hi,

    You will need to copy the template file from wp-content/plugins/a-z-listing/templates/a-z-listing.php into your theme at the root folder e.g. wp-content/themes/your-theme/a-z-listing.php. Once you’ve copied the template you can customise to suit. I haven’t checked whether you need the WP_Post object loaded, but if it isn’t needed I believe the following modification to lines 57-59 will do the job:

    <a href="<?php $a_z_query->the_permalink(); ?>">
    	<?php $a_z_query->the_title(); ?>
    </a>
    <?php the_terms( $a_z_query->get_the_item_id(), 'year', '(', ', ', ')' ); ?>
    

    This will print the terms linked to their own page (according to the ‘the_terms’ documentation). An alternative, if you want the terms linked to the post is to use get_the_terms, which returns an array that you’ll need to iterate over to build the list. You can then place the output either inside the <a> to link the whole list to the post, or after the <a> to leave the list unlinked:

    <a href="<?php $a_z_query->the_permalink(); ?>">
    	<?php $a_z_query->the_title(); ?>
    </a>
    <?php
    $terms = get_the_terms( $a_z_query->get_the_item_id(), 'year', '(', ', ', ')' );
    if ( ! empty( $terms ) ) {
    	print '(';
    	$first_iteration = true;
    	foreach ( $terms as $term ) {
    		if ( $first_iteration ) {
    			$first_iteration = false;
    		} else {
    			print ', ';
    		}
    		print $term->term_name;
    	}
    	print ')';
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Display Category in brackets after Post name’ is closed to new replies.