Topic: loop for in shortcode

this would be logical?

    // start shortcode
   public static function _shortcode($attributes) {  
    // Extract
    extract($attributes);
   // photo
    if (isset($photo)) $photo = $photo; else $photo = '"';
    // title
    if (isset($title)) $title = $title; else $title = '';
    return
        for ($i = 1; $i <= 10; $i++) {
        echo ('<a href="'.$photo[$i].'">
                    <img src="'.$photo[$i].'" title="'.$title[$i].'"/>
                 </a>'); 
         }
    }

<!-- in web -->

{Nameshortcode 
    photo1="http://www.example.com/1.png" title1="example1" 
    photo2="http://www.example.com/2.png" title2="example2" 
    photo3="http://www.example.com/3.png" title3="example3"
}
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: loop for in shortcode

        class Gallery {
            public static function _shortcode($attributes) {  
                // Init Vars
                $result = '';
                $_files  = array();
                $_titles = array();
                // Extract
                extract($attributes);
                // files
                if (isset($files)) $files = $files; else $files = '';
                // title
                if (isset($titles)) $title = $titles; else $titles = '';
                $_files = explode('|', $files);
                $_titles = explode('|', $titles);
                foreach ($_files as $key => $value) {
                    $result .= '<a href="'. $value.'"><img src="'.$value.'" title="'.(isset($_titles[$key])?$_titles[$key]:'').'"/></a>';
                }
                return $result;
            }
        }
        Shortcode::add('gallery', 'Gallery::_shortcode');

Usage:

{gallery files="path/to/file1.png|path/to/file2.png|path/to/file3.png"}
{gallery files="path/to/file1.png|path/to/file2.png|path/to/file3.png" titles="Title1|Title2|Title3"}
Monstra Loves You! Give some love back!

3 (edited by nakome 2012-09-19 20:00:46)

Re: loop for in shortcode

Thanks  wink

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website