Sublime directory Surf the web anonymous Pagerank Monitor


php Image Display

YMC
Sat 25 July 2009, 09:32 pm GMT +0200
I am trying to make a header for a Wordpress blog that is made up of 5 random images. I tried getting one of the WP widgets to work and while it did not throw any errors, it didn't display any of the images either.

After spending way too long messing with it, I thought maybe I could do my own thing and come up with exactly what I wanted instead of making something else work.

I think I may have stumbled onto a really slick way to generate the random numbers except my efforts lead to no image being displayed either. lol

So, here's what I've got...

A sub-directory in my theme's directory called random-image. In it are files named 1.jpg, 2.jpg, 3.jpg etc.

I'm getting a random number ($random_1).

I had hoped I could add on the directory and .jpg extension when making the image display. That didn't seem to work so I created another variable $file_1 and took the random number and added ".jpg" to it. Again, no luck on getting the image to display.

Both $random_1 and $file_1 contain the correct information and the values for both display fine. But, I can't seem to use them to display the images.

My thinking is to do something like this within the <?php     ?>

General random #1.
Create file name #1.
Display image #1.

Generate random #2.
Create file name #2.
Display image #2.

etc.


Ideally, I would like to use the images side by side as my page header so there may need to be divs or spans to format each image so I'm thinking that the images have to be displayed from within the php code.

I have been all over the web and nothing seems to work. I don't know if there's something special I need to do because it's WordPress, the image display code is wrong or I can't build a file name the way I am.

Any help would be greatly appreciated.


YMC
Sat 25 July 2009, 10:47 pm GMT +0200
After walking away for a while and coming back to this it seemed more and more likely that this had to be a Wordpress issue - it is!

Changed my search strategy and quickly found the solution on the wordpress forums - http://wordpress.org/support/topic/278852.

Perhaps my post will help someone else as I've spent way to much time on something that should have been simple.

Ultimately the issue was taking the image display call out of the php and using php within the img tag and using a WP variable for the directory where the template files are located...

<img src="<?php echo bloginfo('template_url'); ?>
/random-image/<?php echo $file_1;?>" alt="something goes here" />

lumpersservice
Sat 12 December 2009, 03:50 pm GMT +0100
I also get stuck on that header images issue...I made some search and found dynamic header plugin at wordpress...it does have an issue on the image resize..cheers

alfredthomson
Thu 5 August 2010, 06:42 am GMT +0200
is $random_1 int variable?

infoman66
Tue 21 September 2010, 07:06 pm GMT +0200
I am a similar problem to them.
I needed to automate the process so that users can upload images to the server and that they appear random in the header, regardless of the image name ...
I used a php script to read the content directory, and for its display random image java script ...

vipandiversity
Fri 22 July 2011, 10:27 am GMT +0200
Its the best funchion for show your and other Images with the help of PHP.

shanmarsh2
Thu 6 October 2011, 09:28 am GMT +0200
Looking for code for displaying image in PHP page.
I have tried but not working.

hostnametoip
Thu 24 November 2011, 01:29 pm GMT +0100
Uses an external PHP file to auto retrieve all images within a directory to show on the fly.
Customize the album's dimensions as desired, such as 3 by 2 images, 4 by 5 images etc.
Ability to sort the display order of the images by file or date, in ascending or descending order.

mark_john
Thu 24 November 2011, 03:14 pm GMT +0100
How to display Image in php page- PHP Development. Visit Dev Shed to discuss How to display Image in php page.

mark_john
Fri 9 December 2011, 11:40 am GMT +0100
 hi all i am working on a website that will display projects and many images for each project. i want to make an interface

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional