PHP
$meta = get_post_custom($post->ID);
$images = $meta['img1'][0]; // urls separated with comma
$images = explode(',', $images);
foreach ($images as $image) {
echo '{image : '.$image.', title : "Credit: x"},';
};
Output:
{image : 'http://localhost/slideshow/1.jpg', title : 'Credit: x'},
{image : 'http://localhost/slideshow/2.jpg', title : 'Credit: x'},
{image : 'http://localhost/slideshow/3.jpg', title : 'Credit: x'},
{image : 'http://localhost/slideshow/4.jpg', title : 'Credit: x'}, // last comma, just after }
I would like to remove the last commented comma in output.
This is exactly what I'm trying to get:
Desired output:
{image : 'http://localhost/slideshow/1.jpg', title : 'Credit: x'},
{image : 'http://localhost/slideshow/2.jpg', title : 'Credit: x'},
{image : 'http://localhost/slideshow/3.jpg', title : 'Credit: x'},
{image : 'http://localhost/slideshow/4.jpg', title : 'Credit: x'}