To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Newbies

Newbies Help for those who are just getting started

Reply
 
Thread Tools Rate Thread Display Modes
Old 10-31-2009, 11:50 PM   #1
biagio111
Junior Member
 
Join Date: Oct 2009
Posts: 1
Help setting thumbnail by looping through image array

Hello everyone. First post here!

We keep a Wordpress blog using a tweaked Wordpress theme called Hybrid News. This sets up a front page that has an excerpt and a thumbnail image. You can see what I'm talking about here:

http://www.jokeandbiagio.com

Problem is, setting a thumbnail image isn't possible from an iPhone, and it's tough to write fast posts that look good.

What I'm trying to set up is a way to LOOP through an image array, based on the category I set for the post.

So if a post is in category "SQ" for instance, I'd like to have an array of 3 images. A post to "SQ" would use image 1, next post would use image 2, next post image 3, following post would then start over at image 1.

Right now I'm using this code, which only has a default image per category, and adds the thumbnail to the appropriate slot on the theme's front page:
PHP Code:
<?php
                
if ( in_category( 'SQ' ) )
                
$default_image = 'http://www.jokeandbiagio.com/wp-content/uploads/2009/09/twitterview_scream_queens_th.jpg';
                elseif (
in_category( 'field' ) )
                
$default_image = 'http://www.jokeandbiagio.com/wp-content/uploads/2009/10/Mission-X-Tommy-Gun-Garage.jpg';
                elseif (
in_category( 'office' ) )
                
$default_image = 'http://www.jokeandbiagio.com/wp-content/uploads/2009/09/typewriter-keys-blue_med.jpg';
?>

<?php get_the_image( array( 'custom_key' => array( 'Medium', 'Feature Image' ), 'default_size' => 'medium', 'default_image' => $default_image ) ); ?>
How could I build a "well" of images so instead of having one default, there's 3, and each time I post, the thumbnail becomes the next image in the array? I'm figuring it's using some kind of loop. I admit to being a PHP newbie, and while I found some interesting information here:

http://www.efishdesign.com/tutorials/php.php#part4

and on this forum here:

http://www.webdeveloper.com/forum/ar.../t-112743.html

I haven't been able to figure out how to implement the idea of an image array loop into the above code.

Thanks so much for any help!
biagio111 is offline   Reply With Quote
Old 11-05-2009, 12:15 AM   #2
jkurrle
To code, or not to code?
 
jkurrle's Avatar
 
Join Date: Jul 2004
Location: Miami, FL
Posts: 425
An idea

You might simply count the number of each post, then divide by 3 and look at the remainder. Using a simple Switch-Case set of statements, you could display a particular image for anything with no remainder, a remainder of 1, or a remainder of 2. Simple and relatively easy to do...
__________________
99 little bugs in the code, 99 bugs in the code,
fix one bug, compile it again...
101 little bugs in the code....
jkurrle is offline   Reply With Quote
Reply

Bookmarks

Tags
array, images, loop


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 04:28 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.