Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hi,

I'm trying to make a shortcode that will list all the images in a certain folder on my server. The reason I want to do this is so I can upload images to a folder, then have the shortcode list all the images in that folder and put them into a jquery slider gallery.

What I've got so far is this:
Code: Select all
   // 4.
   // Galleri
   // Usage: [galleri foldername]

   $FUNCS->register_shortcode( 'galleri', 'galleri_handler' );
   function galleri_handler( $params, $content=null ){
      global $FUNCS;

      extract( $FUNCS->get_named_vars(array(
         'folder' => '',
      ), $params) );

        $dir = "couch/uploads/image/artikkler/$folder/";
        $images = glob($dir.'*.jpg');

       return print_r($images, true);
       
   }


This is a decent start, I get a array listing of the filenames and their paths. But I dont know where to go from here. Does anyone know how I can convert this array view to something more usable, like a <img src=""> tag for each filepath?

I am obviously not very good with PHP so I would appriciate all help. I undertand you have to use return to get the shortcode to work properly in editable regions, but I can't figure out how to list these variables as something I can use to display images.

Does anyone have any suggestion on a better way of doing this?
I figured it out. This is doing what I need. Hope it can be usefull for someone else, otherwise just delete the post..

Code: Select all
   // 4.
   // Galleri
   // Usage: [galleri foldername]

   $FUNCS->register_shortcode( 'galleri', 'galleri_handler' );
   function galleri_handler( $params, $content=null ){
      global $FUNCS;

      extract( $FUNCS->get_named_vars(array(
         'folder' => '',
      ), $params) );

    $dir = "couch/uploads/image/artikkler/$folder/";
    $return = '';
    $images = glob($dir.'*.jpg');
        foreach ($images as $post) {
        $return .= '<img src="../'.$post.'">';
      }
       
      return $return;   
   }
2 posts Page 1 of 1