Grow your CSS skills. Land your dream job.

Ending last value of Custom Field with a dot?

  • # February 11, 2013 at 1:54 pm

    Hi all,

    I’m struggling with Custom Fields a bit.

    I’m displaying certain ‘Facilities’ via this command:

    < ?php $facilities = get_post_meta($post->ID, ‘Facilities’, false); ?>
    < ?php foreach($facilities as $facilitieslist) { echo ''.$facilitieslist.', '; } ?>

    I’d like to end each last value with a dot (“.”)

    How would I do this, anyone?

    Cheerios

    # February 11, 2013 at 3:00 pm

    I got a little closer thanks to php.net :)

    The last value of the “Facilities” Custom Field now gets dotted. I also sort all values alphabetically. I wonder what you guys think of the syntax – I’m lousy at PHP, and tag too much I think?

    Here’s my code:

    < ?php $facilities = get_post_meta($post->ID, ‘Facilities’, false); ?>
    < ?php sort($facilities); ?>
    < ?php $lastfacility = array_pop($facilities); ?>
    < ?php foreach($facilities as $facilitieslist) { echo ''.$facilitieslist.', '; } ?>
    < ?php echo ''.$lastfacility.'.'; ?>

    Cheers.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".