• Resolved frobitz

    (@frobitz)


    Hi,

    I’d like my blog posts to have a tag list display like this:

    ‘This post tagged as something, something, something and something.’

    Where ‘something’ is a tag link associated with the post. The stumbling block is I can’t find any example where it is possible for the last seperator to be a string ‘and ‘ and not the string ‘, ‘.

    Anyone seen this done? I’m sure I can’t be the only person to attempt this!

    Thanks

    Rich

Viewing 2 replies - 1 through 2 (of 2 total)
  • instead of the usual:
    <?php the_tags( '<p>This post tagged as ', ', ', ' </p>'); ?>

    you could use:

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
    $i=0; $count=count($posttags); echo '<p>This post tagged as ';
    foreach($posttags as $tag) {
    echo $tag->name; $i++;
    if ($i == $count-1) { echo ' and '; }
    elseif ($i == $count) { echo ''; }
    else { echo ', '; }
    }
    echo '.</p>';
    }
    ?>

    not optimized, but seems to work ??

    Thread Starter frobitz

    (@frobitz)

    Thats fantastic, works a charm.

    Thanks very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Grammatical tag list with ‘and’ before last tag’ is closed to new replies.