HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


[Resolved] Image fader

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#93814 (In Topic #18735)
Avatar

Community saint

Is it possible to make the image fader either choose random images or use a "last uploaded, first displayed" (LIFO)? When the page opens, the fader always starts with the first uploaded image and rotates through the gallery in uploaded order (FIFO).

I've looked at BLOCK_MAIN_IMAGE_FADER.tpl, but I don't see anything that allows what I want. But then again, I know just enough about this to really screw up my site!  :lol:

Steve
Back to the top
 
Posted
Rating:
#93815
Avatar

Community saint

Looks like you will need to change /sources/main_image_fader.php and not the template.

To change to LIFO order, you will probably need to change:

Code

$image_rows=$GLOBALS['SITE_DB']->query_select('images',array('thumb_url'),array('cat'=>$cat),'',100/*reasonable amount*/);
 to something like:

Code

$image_rows=$GLOBALS['SITE_DB']->query_select('images',array('thumb_url','add_date'),array('cat'=>$cat),'ORDER BY add_date DESC',100/*reasonable amount*/);
Note that I haven't tested it, but I can't think of any reason why it wouldn't work.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#93817
Avatar

Community saint

temp1024 said

Looks like you will need to change /sources/main_image_fader.php and not the template.

To change to LIFO order, you will probably need to change:

Code

$image_rows=$GLOBALS['SITE_DB']->query_select('images',array('thumb_url'),array('cat'=>$cat),'',100/*reasonable amount*/);
 to something like:

Code

$image_rows=$GLOBALS['SITE_DB']->query_select('images',array('thumb_url','add_date'),array('cat'=>$cat),'ORDER BY add_date DESC',100/*reasonable amount*/);
Note that I haven't tested it, but I can't think of any reason why it wouldn't work.

Thanks, temp, for your help.

I can think of one reason why it didn't work: you're working with an older version and the syntax is different.  ;)   But anyway, once I seen it was just a database query, I played around with the ORDER BY clause but just kept getting parse errors.
Here's the code:

Code (php)

$image_rows=$GLOBALS['SITE_DB']->query('SELECT id,thumb_url,url,title,comments FROM '.get_table_prefix().'images WHERE '.$cat_select,100/*reasonable amount*/);
 

I added "add_date" to the SELECT string and placed the "ORDER BY add_date DESC" (with proper quoting) in different spots but nothing seemed to work. Any suggestions where to stick it? (Careful how you answer that one! O_o) I'm sure I need to change the ORDER BY clause a little but I'm not sure to what.

Steve
Back to the top
 
Posted
Item has a rating of 5 (Liked by Chris GrahamLiked by Jean)  
Rating:
#93818
Avatar

Community saint

sholzy said

I can think of one reason why it didn't work: you're working with an older version and the syntax is different.  ;)
Good guess. I'm still stuck in the dark ages of v7.01
Any suggestions where to stick it? (Careful how you answer that one! O_o)

Expand: I know where you can stick it I know where you can stick it



Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#93819
Avatar

Community saint

 :lol:  :thumbs: I was almost afraid to expand that box not knowing what I would find in there!

Thanks, temp. It works great! I was so close. I had it in that spot, but I used a comma instead of a period after $cat_select.  :dry:

One more thing to figure out on this fader and it will be completed…

Steve
Back to the top
 
Posted
Item has a rating of 5 (Liked by sholzyLiked by Fletch)  
Rating:
#93820
Avatar

Community saint

sholzy said

 :lol:  :thumbs: I was almost afraid to expand that box not knowing what I would find in there!
So my plan worked perfectly!

sholzy said

Thanks, temp. It works great!
:thumbs:

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Item has a rating of 5 (Liked by sholzyLiked by Fletch)  
Rating:
#93821
Avatar

Community saint

Just had a thought about selecting random images. Try this:

Code

$image_rows=$GLOBALS['SITE_DB']->query('SELECT id,thumb_url,url,title,comments FROM '.get_table_prefix().'images WHERE '.$cat_select.' ORDER BY RAND()',100/*reasonable amount*/);

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#93822
Avatar

Community saint

temp1024 said

Just had a thought about selecting random images. Try this:

Code

$image_rows=$GLOBALS['SITE_DB']->query('SELECT id,thumb_url,url,title,comments FROM '.get_table_prefix().'images WHERE '.$cat_select.' ORDER BY RAND()',100/*reasonable amount*/);

This works too, and for my purposes fits just perfect.  :thumbs:  Thanks again, temp!

This would make a nice configuration option for main_image_fader. (hint hint, Chris…)  :thumbs:

Steve
Back to the top
 
Posted
Rating:
#93823
Avatar

Community saint

I should add, only the first image shown is random, after that they're shown in order. I think a truly random order would require no caching and a db call for each image being displayed, unless all the images (file names?) could be put into an array and randomly chosen from that array.

Steve
Back to the top
 
Posted
Rating:
#93824
Avatar

Yes, but you can add a block without cacheing, cache="0". Oh, and yes the order is determined in a queue, so there aren't repeats - it's not that each cycle is a new pick.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#93825
Avatar

Community saint

Ah, yes, the caching option. I added that block a several months back and forgot those options under the advanced section. I turned caching off. Thanks for the reminder, Chris.

Steve
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: