Avatar bryan.toth asked

How do I limit the # of images displayed in an image gallery?

Is there any way to limit the number of photos displayed in a widgetkit image gallery?

Let's say I have 100 photos in my folder but only want to, randomly, show 50 of them.

Can that be done with an alteration to the code?

Thanks!
~ Bryan

  • Widgetkit
  • Feature Request
  • General Question

11 Answers

12

Avatar david.carroll answered

Hi Bryan,

This is definitely a new feature request that is not currently supported in the WidgetKit Plugin. However, if you are interested in applying this with custom code, you can do so if you are comfortable with the disclaimer below:

DISCLAIMER: Follow Instructions Below At Your Own Risk

The instructions below involve modifying files on the server. If you do this wrong on the live server, you could cause an issue with WordPress loading at all until reversing your steps. Also Note: You will need to reapply these changes after updating the WidgetKit Plugin if these changes are not included. For this reason, only proceed if you are comfortable doing so.

-> Also, see another Custom Feature added for WidgetKit Twitter

Modify Gallery Loading and Option Saving Code:

Step 1: Locate the File to Modify

/widgetkit/widgets/gallery/gallery.php

Step 2: Locate the lines below:

// random order  
if(count($images) && isset($settings['order']) && $settings['order'] =="random") {  
   shuffle($images);  
}

And add the following lines just below:

//DC: Apply image gallery limit logic.  
if(is_numeric($settings['limit'])){  
    $images = array_slice($images, 0, $settings['limit']);  
}

Step 3: Locate the lines below:

if ($data['settings']['height']!="auto") {  
    $data['settings']['height'] = intval($data['settings']['height']);  
}

And add the following lines just below:

//DC: New Setting for Gallery Image Limit  
if ($data['settings']['limit']!="auto") {  
    $data['settings']['limit'] = intval($data['settings']['limit']);  
}

Add Limit Setting to Gallery Edit Page:

Step 1: Locate the File to Modify

/widgetkit/widgets/gallery/gallery.xml

Step 2: Locate the lines below:

<setting name="height" label="Height" type="text" default="auto" />

And add the following lines just below:

<setting name="limit" label="Image Limit" type="text" default="auto" />

Test New Settings:

Edit one of your WidgetKit Gallery settings.
Look for the new setting: Limit
Change to some number like 3 to make the test obvious.
Change the Order Dropdown setting to: Random

Let me know if I was able to answer your question.

Best Regards,

David Carroll

Edited

3

Avatar david.carroll answered

Although I was able to provide the custom code to make this work, there isn't any guarantee it will be added to the plugin by the YOOtheme Development Team. They will need to evaluate whether or not this feature as it is presented is complete enough to release AS-IS. What sort of other usability challenges will it introduce and what additional support will be required for this feature.

I say this simply to state it's not guaranteed this will be added to the plugin. One way to improve its chances is for the other members to comment and add a PLUS 1 to the question.

I'll keep you posted if I hear anything.

Best Regards,

David Carroll

1

Avatar racket answered

May 2013: Any chance to get this implemented by default? Works like a charm and is super useful.

1

Avatar goose answered

yes, would be great to have that functionality!

1

Avatar juergen.kronz answered

Hi,

I need the same feature, ist it possible in Joomla too?

And when get it implemented by default?

1

Avatar manege answered

I guess development team just forgot to implement this feature with initial publishment of this widget
This is a MUST HAVE !
Please implement it asap!
Thank You

1

Avatar jeremias.wirz answered

Solution for Joomla and Widgetkit 2.7.7

Open and edit file /administrator/components/com_widgetkit/plugins/content/custom/views/edit.php

Locate line 38 "</div>" and add the following lines just below:

<div class="uk-form-controls uk-form-controls-condensed">  
 <label><input class="uk-form-width-small" type="text" ng-model="content.data['limit']"> {{'Limit' | trans}}</label>  
</div>

Save file.

Next open and edit file /administrator/components/com_widgetkit/plugins/content/custom/plugin.php

Locate line 38 "shuffle($newitems);" and add the following lines just below:

if($content['limit']){    
 $newitems = array_slice($newitems, 0, $content['limit']);  
}

Save file.

Go to Joomla Backed and edit one of your Widgetkit item settings.
Look for the new setting: Limit
Change to some number you like

0

Avatar bryan.toth answered

Perfect!
Your directions were crystal clear!

Thanks so much!
Looking forward to seeing this built into a future widgetkit update!

Thanks again!

0

Avatar bryan.toth answered

Agreed.
I'm getting tired of adding the code every update. haha

0

Avatar lisa.hine answered

@jeremias.wirz, I tried to follow your instructions .. I'm in Joomla 3.6.5 and WidgetKit 2 dot whatever (it's up to date). I can see the new Limit field (which I've set to 8), but it doesn't affect how many images actually show up. You can see the widget in question here: http://build.eatonrealty.com/.

I've tried grid slider, gallery, and slideshow. What do you recommend?

Thank you!!!
LH

Know someone who can answer? Share a link to this question via email or twitter.