Wordpress Post Images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DysPatch
Forum Newbie
Posts: 1
Joined: Sat Jan 10, 2009 5:38 pm

Wordpress Post Images

Post by DysPatch »

Hi there,

I am generally new to PHP and Wordpress, but I went through a long winded Wordpress tutorial and I am fairly comfortable working with it now. I am a Java programmer but not really a PHP programmer but if you know one language its not far from the others.

Anyways, on to the question at hand. I would like to have each post have a different background image. Essentially I would like to have it cycle through 3 images. First post would have image 1, second post would have image 2, third post would have image 3, the fourth post would have image 1 again. Anyways How would I have the program call each image?

Would you like some of my wordpress code to help you?
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Wordpress Post Images

Post by it2051229 »

here's a java code and convert it to php

Code: Select all

 
String[] images = new String[3];
images[0] = "Image1.JPEG";
images[1] = "Image2.JPEG";
images[3] = "Image3.JPEG";
 
// assuming the posts are arranged in an array(because it would be quite complicated using database connection strings in java and post it here)
String[] posts = new String[4];
posts[0] = "This is Post 1";
posts[1] = "This is Post 2";
posts[2] = "This is Post 3";
posts[3] = "This is Post 4";
 
// then we display the posts with background
int j = 0;
for(int i  = 0; i < posts.length; i++)
{
     // we set the background of the post using images[j]
     //.....
     //.....
     // then we display the post using posts[i]
     //.....
     //.....
 
     if(j < images.length)
     {
          j++;
     }
     else
     {
          j=0;
     }
}
 
Post Reply