1
antifmradio
random image in header? possable or no?

is it possable to place a banner system or random image code into the HEADER of themes / skins?

i havent tried simply copying any code directly into it yet but i also didnt want to take the time to setup the code for randomizing only to have it busy up my pages anyway lol

2
antifmradio
Re: random image in header? possable or no?

bump

just looking for info on IF i can place phpADS code or any php code directly into the header location of a theme.
Wanted to know if XOOPS recognizes this stuff

3
stefan88
Re: random image in header? possable or no?
  • 2008/10/17 4:56

  • stefan88

  • Community Support Member

  • Posts: 1086

  • Since: 2004/9/20


Hi,

yes, it is possible and XOOPS will recognize it. But as XOOPS uses smarty for theming you need to put php code in respective smarty tags for php:

<{php}>
//...YOUR CODE GOES HERE...

<{/php}>


..

4
antifmradio
Re: random image in header? possable or no?

see now i never would have thought of that
thanks very much stefan

ill write up a code and submit it to everyone else with instructions for editing to their own use.

Thanks again
Later all

5
ghia
Re: random image in header? possable or no?
  • 2008/10/17 12:20

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


You may find also inspiration in the code of xcGal, which has a random images block.

6
antifmradio
Re: random image in header? possable or no?

Quote:

ghia wrote:
You may find also inspiration in the code of xcGal, which has a random images block.


correct but with that code i cant tell it to specify where to get images from.
Im creating a RANDOM HEADER code which will pull images from a seperate folder, outside of XOOPS installation folders.
This way the header images can be customized by the site owner for their brand of site

7
mboyden
Re: random image in header? possable or no?
  • 2008/10/17 17:06

  • mboyden

  • Moderator

  • Posts: 484

  • Since: 2005/3/9 1


Absolutely doable with PHP code embedded in your templates. Below is an example for what I did for one site. This code reads files from a (definable) directory, selects one randomly, and returns the filename. The code supports multiple themes (drawing from a callable directory within the theme directory) and allows usage/calls in multiple locations in the theme. However, it's not designed to provide size information (height/width) on different file sizes.

First, define the function somewhere in your theme file:
<{php}>
function 
getRndImgURL($path) { // Display Random Image from File Path
    
$i 0;
    
$dir = @opendir(XOOPS_ROOT_PATH.'/themes/'.$GLOBALS['xoopsConfig']['theme_set'].'/'.$path);
    while ( 
false !== ($filename readdir($dir)) ) {
        if ( 
preg_match("/(.gif|.jpg|.png)$/"$filename) ) { // image filter
            
$images[$i] = $filename;
            
$i++;
        }
    }
    
closedir($dir);
    
mt_srand( (double)microtime() * 1000000 );
    
$choice array_rand($images);
    return 
XOOPS_URL.'/themes/'.$GLOBALS['xoopsConfig']['theme_set'].'/'.$path.'/'.$images[$choice];
}
<{/
php}>

Then call the function when needed:
<img src="<{php}> echo getRndImgURL('img/sidebar'); <{/php}>" alt="" width="158" height="116" />div>

You can likely tailor this pretty easily to meet your needs. Good luck!
Pessimists see difficulty in opportunity; Optimists see opportunity in difficulty. --W Churchill

XOOPS: Latest | Debug | Hosting and Web Development

8
antifmradio
Re: random image in header? possable or no?

thanks mboyden
the one im working on DOES let you set height and or width

also, youll simply have to copy the code into the respective theme header location

if your site has mutiple themes and you DONT want random images in one of them, just leave the code out.


Also say you want different images showing up for different themes, simple
then just create all the images you want and place them in your server
Theme 1 images in its own folder
Theme 2 images in its own folder
Theme 3 images in its own folder
and so on.
You can set the height / width to be different in each one of the themes to match the size of the theme main table width or the images themselves.

9
antifmradio
Re: random image in header? possable or no?

ok i messed up somewhere
i dont get what i did wrong

my code starts with

and ends with
?>

so i change the ends to have
the smary coes instaed but i think that didnt work
cause my entire page and site went blank

I came back here and used the example above changing

$dir = @opendir(XOOPS_ROOT_PATH.'/themes/
to
$dir = @opendir(XOOPS_ROOT_PATH.'/themes/headimages/

and
return XOOPS_URL.'/themes/
with
return XOOPS_URL.'/themes/headimages

Now i am alittle stupmed because i took this new code
and placed it directly in the header area of theme.html
just after it i placed the " call " code
which is the same code as above
This is it


but it didnt work


Am i placing the original code in the wrong plac?
and if so, where does it go in theme.html
cause obviously i need to place the CALL code in the header area

10
mboyden
Re: random image in header? possable or no?
  • 2008/12/4 1:54

  • mboyden

  • Moderator

  • Posts: 484

  • Since: 2005/3/9 1


when I cut and paste the "insert" code, I added an extra
tag that doesn't belong. Remove that and try again.

The function code needs to be placed before the function is called, but otherwise, it shouldn't exactly matter where it is.

As to rewriting $dir, if you change the whole thing just make sure that you're putting the files there, in this case xoopsroot/themes/headimages, but that might confuse XOOPS, so realistically you want a 'headimages' subdirectory in each theme directory and then call it this way (but don't rewrite the $dir code, and make the width/height match your particular needs):



clear as mud?
Pessimists see difficulty in opportunity; Optimists see opportunity in difficulty. --W Churchill

XOOPS: Latest | Debug | Hosting and Web Development

Login

Who's Online

473 user(s) are online (338 user(s) are browsing Support Forums)


Members: 0


Guests: 473


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits