Hi there ModX team,
This is the first post I have made. I really like ModX and I am using it to develop a website which will ’go live’ soon.
I have been fiddling with CMS’s for many years and like a lot of people have downloaded most of the free ones. This is the best by far.
If it is of any use to anyone I will share a few simple changes I made to an existing snippet to make it
do what I wanted.
I needed a random picture that was linked to a page on the site. We also wanted some text beneath the
picture to make it look more like a ’profile’.
1. Create a new snippet called RandomAd.
$folder = 'assets/images/ads';
$i = 0;
$imgDir = opendir ($folder);
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{ $images[$i++] = $file; }
}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $images[rand( 0,sizeof( $images ) -1 )];
$imageid = substr($image_name,0,strpos($image_name,'.'));
$image_name = $folder . '/' . $image_name ;
$imgSize = GetImageSize( $image_name );
//ends script if no images found
if ( $i == 0 )
die();
echo "<a href=index.php?id=$imageid>";
echo( "<center><img border=0 src=\"" . $image_name . "\"" . $imgSize[3] . " /><p>\n" );
@include("$folder/$imageid.txt") ;
echo "</a></center>";
return ;
2. Create a subdirectory of images (I called it ads)
3. Create the page that you want to link to and note the number that ModX assigns to it. (Eg 106)
4. Upload a jpg or gif file of the correct size to images/ads and name it based on the number from step 3. (Eg 106.jpg)
5. Upload a text file to the same directory and also name it after the number assigned in step 3 (106.txt)
6. Call it as usual from where you want. I use the [!RandomAd!] methodology, but you could use [[RandomAd]]
You can see it in action at
www.thespidersart.com/new/1/
in the area called Advertiser Profile. There are only three ’advertisers’ at the present time.
I really appreciate the hard work and dedication of all the people associated with ModX
Geoff