• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: A quick trick to display a random image
PostPosted: Fri Oct 05, 2007 5:12 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 6587
Location: Fernie British Columbia, Canada
Given images named header_1.jpg, header_2.jpg, ... header_10.jpg this code will pick a random one
on every page load.

Code:
{capture assign='num'}{1|rand:10}{/capture}{* generate a random number between 1 and 10, assign it to 'num *}
<img src="uploads/header_{$num}.jpg" width='468' height='50'/>

_________________
Follow me on twitter
--
if you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
----------------
Don't make me angry..... you won't like me when I'm angry....


Last edited by calguy1000 on Sat Oct 06, 2007 7:44 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: A quick trip to display a random image
PostPosted: Sat Oct 06, 2007 6:37 am 
Offline
Power Poster
Power Poster

Joined: Mon Nov 06, 2006 7:55 pm
Posts: 561
Location: Helsinki, Finland
I love these tips! And javascript alternatives like this.

Thanks,

K


Top
 Profile  
 
 Post subject: Re: A quick trip to display a random image
PostPosted: Sat Oct 06, 2007 12:20 pm 
Offline
Support Guru
Support Guru

Joined: Mon Jul 24, 2006 3:27 pm
Posts: 3690
Location: Paris
KO wrote:
I love these tips! And javascript alternatives like this.

The power of this tip is its server side non javascript nature. And shortness.
Pierre M.

_________________
-- Pierre, support team member. comodérateur du forum francophone.
Please read "how to submit installation/support requests" before posting. Don't send private messages to ask for support.
Want to contribute to CMSms ? Improve the wiki with your forum account.


Top
 Profile  
 
 Post subject: Re: A quick trip to display a random image
PostPosted: Sat Oct 06, 2007 4:31 pm 
Offline
Power Poster
Power Poster

Joined: Mon Nov 06, 2006 7:55 pm
Posts: 561
Location: Helsinki, Finland
Yeah... that's the cool thing with it. It's just so easy for everyone copy javascript code from somewhere and stick it in wishing people don't have noscript enabled. It's amazing to see what kind of crap high profile companies and their web pages put out without javascript.


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Thu Oct 11, 2007 8:23 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri May 05, 2006 7:55 pm
Posts: 293
Location: New Haven, CT
Hi all,

I think the poster KO was saying, thanks for an alternative to using javascript :D! You two are in agreement, maybe it is language barrier? :D

_________________
If I help you, please give good karma. If I'm rude, give me bad karma. I like to know where I balance out in the end :).


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Fri Oct 12, 2007 2:31 pm 
Offline
Support Guru
Support Guru

Joined: Mon Jul 24, 2006 3:27 pm
Posts: 3690
Location: Paris
Yes, my mistake. You are right : rereading KO, I understand now he means "an alternative to using javascript" as you say. Thank you for the language clarification.

Pierre

_________________
-- Pierre, support team member. comodérateur du forum francophone.
Please read "how to submit installation/support requests" before posting. Don't send private messages to ask for support.
Want to contribute to CMSms ? Improve the wiki with your forum account.


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Sat Oct 13, 2007 6:33 pm 
Offline
Power Poster
Power Poster

Joined: Mon Nov 06, 2006 7:55 pm
Posts: 561
Location: Helsinki, Finland
:) No worries. No one's been offended. English is not my mother language and I write total garbage most of the time anyway.

Still nice solution and thanks to Calguy!


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Tue Jan 15, 2008 6:42 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Oct 25, 2006 8:29 pm
Posts: 4986
Location: Raalte, the Netherlands
Based on this tip from Calguy1000, the variant to create the random background for the header-container....

This should be put in the template.

Replace the:

Code:
<div id="header">


With:

Code:
{capture assign='num'}{1|rand:10}{/capture}
<div id="header" style="background-image: url(uploads/header_{$num}.jpg)">


And dont forget to remove the background image for the header, in the stylesheet, as it already is called here.

Ronny


Last edited by RonnyK on Wed Jan 16, 2008 6:10 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Wed Jan 16, 2008 2:52 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Sun Jan 22, 2006 3:24 am
Posts: 435
Location: Syracuse, NY
OK, I'm a little dense, so I think I need a bit more information...

what is this 'capture'... php?

_________________
Michael


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Wed Jan 16, 2008 3:08 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Sat Mar 24, 2007 8:28 am
Posts: 383
Location: Long Beach, CA
I haven't tried but I believe you just stick that {capture... } smarty tag in your page template and it should work.


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Wed Jan 16, 2008 3:36 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Sun Jan 22, 2006 3:24 am
Posts: 435
Location: Syracuse, NY
Yes, it works...but why? What is it?

_________________
Michael


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Wed Jan 16, 2008 3:41 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Sat Mar 24, 2007 8:28 am
Posts: 383
Location: Long Beach, CA
it displays the images (which you need to have somewhere in advance)


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Wed Jan 16, 2008 4:02 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Sun Jan 22, 2006 3:24 am
Posts: 435
Location: Syracuse, NY
Guys, I know what it's supposed to do and I know that I just need to put the code in the template. What I want to know is what is 'capture'... is it a php function, or what?

_________________
Michael


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Wed Jan 16, 2008 4:24 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 6587
Location: Fernie British Columbia, Canada
see: http://smarty.php.net/manual/en

Required reading for CMS users.

_________________
Follow me on twitter
--
if you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
----------------
Don't make me angry..... you won't like me when I'm angry....


Top
 Profile  
 
 Post subject: Re: A quick trick to display a random image
PostPosted: Wed Jan 16, 2008 3:59 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Sun Jan 22, 2006 3:24 am
Posts: 435
Location: Syracuse, NY
Thank you.

_________________
Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Arvixe - A CMSMS Partner