How I can handle this shortcode:
[my_gallery]
img01.jpg
img02.jpg
img03.jpg
img04.jpg
[/my_gallery]
I can't understand how to write a function, to handle image files name.
Are you going to put newlines in there between each image? or just spaces? I'll put in both for this example, checking if there's a newline.
You would want something like this in your functions.php:
add_shortcode('my_gallery', 'gallery_function');
function gallery_function($atts, $code=''){
$files=preg_split( '/\s+/', $code ); // Added in from Jan's comment.
foreach($files as $img){
if($img=="")
continue; // ensures that no empty items from the split have entered in, since that is possible with the preg_split
//handle each filename in here.
}
}
It's not perfect.. if you use both spaces and newlines in your shortcode, it'll mess things up - though that could be dealt with in more detail inside the function.
Hope this helps.
preg_split( '/[\n ]+/', $code ), or even just preg_split( '/\s+/', $code ) to split on any whitespace character.
preg_split() you don't need to detect the marker either.