I would like to display the tags of a post different than what’s standard in WordPress. If I’ve understood it correct, all I can do with the regular tags is to display different things between them and at the end.

The tags should be displayed like this:

Read more about tag 1, tag 2, and tag 3
Read more about tag 1 and tag 2

How can I get that “and” word in there?

1 Answer
1

the_tags() is simple for convenience, if you want more control over formatting, use get_the_tags() and output them however you want.

EDIT – quick example for the template:

<?php
$posttags = get_the_tags();

if ($posttags) {

    echo 'Read more about ';

    $tag_count = count( $posttags );
    $count = 0;

    foreach( $posttags as $tag ) {
        $count++;
        if( $tag_count == $count )
            $sep = '.';
        elseif( $tag_count - 1 == $count )
            $sep = ', and ';
        else
            $sep = ', ';
        ?>
        <a href="https://wordpress.stackexchange.com/questions/26183/<?php echo get_tag_link( $tag->term_id ); ?>" title=""><?php echo $tag->name; ?></a><?php echo $sep; ?>
        <?php
    }
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *