wordpress help
- Started
- Last post
- 17 Responses
- forcetwelve
ive got this on the WP forums, but thought id double my exposure and post it here too.
what i have is a site that is a pages/cms type site, ie no blog. i have a 2 column layout - text on the left, and image on the right.
currently i am using categories and the query_posts tag to place the images in the right hand side on each page. the problem with this is i have to have a category for each pages right hand side column.what i would like to do is be able to use a variable(?) which will place the image (from the post) in the image column for each page automatically, without having to have all the categories.
ive looked into custom fields but can't seem to get multiple images in the desired column.
is this possible? thx for any help in advance!
- TResudek0
Hey man - ping me on iChat/AIM and I will help you out. I think I have done just about everything imaginable within Wordpress. Not exactly clear on what you need though...
sn: timothyresudek
- ive added you mate. can you see me?forcetwelve
- Don't know your SNTResudek
- forcetwelveforcetwelve
- bort0
Why use categories to control images? Look at custom fields again. If you can't get them formatted correctly it's likely the product of buggy css rather than the custom fields.
- forcetwelve0
i can get them working - but i'm not sure how to have multiple images?
- forcetwelve0
and how would i go about this?
- bort0
<?php if (get_post_meta($post->ID, 'image-1', true) ) { ?>
<img src="<?php echo get_post_meta($post->ID, 'image-1', true); ?>" width="150" height="150" ></li>
<?php } ?><?php if (get_post_meta($post->ID, 'image-2', true) ) { ?>
<img src="<?php echo get_post_meta($post->ID, 'image-2', true); ?>" width="150" height="150" ></li>
<?php } ?><?php if (get_post_meta($post->ID, 'image-3', true) ) { ?>
<img src="<?php echo get_post_meta($post->ID, 'image-3', true); ?>" width="150" height="150" ></li>
<?php } ?>The conditionals (if statements) are there so if you don't want to include the images on a certain page then they aren't output. If you know you're going to have an absolute number of images on every page then feel free to remove the if statements.
These have to be used in the loop.
- forcetwelve0
legend — thx so much. works perfectly.
- bulletfactory0
I use multiple custom fields on all of my portfolio project pages, they control everything from the images, to the links and details of the project - if you're still stuck - (the post above is great) lemme know and i'll send you the code to my portfolio category single page
- is it similar to that of above? i wouldnt mind a look at your code either way. thx!forcetwelve
- email sent!bulletfactory
- forcetwelve0
how would i put padding on the images there? #img in css?
- bort0
That's one method. You may want to target it more specifically than just img though. Using just img will apply those styles to every image on your site.
So more like this... #mainWrapper .imageColumn img {padding:15px;}
No hash sign either. Unless you've created a id called #img.
- acescence0
in the get_post_meta function, you can also change true to false and get back an array of images with the same field name, so all your custom fields would have the same name. that way you can have none, one, or a thousand images and you don't have to hard-code each field name into your template, just loop thru the array of images.
- Nice!bort
- hmm - sounds interesting. ive changed the true to false. whats next?forcetwelve
- forcetwelve0
thanks for all your help guys. this was the last thing i needed to work out and its now all sorted! appreciate it.
- acescence0
in response to your note over there > ^
- i cant work out where to put that in context of the other code.forcetwelve
- forcetwelve0
acescence — i cant work out where to put that in context of the other code. do you mean replace the whole tag with that?
what does it actualy do?
- acescence0
in the original example, there are 3 custom fields for 3 images, but in a post you can have multiple custom fields that share the same name. that way you don't have to put separate calls to pull out image-1, image-2, etc., you just loop thru one array of all of your images, however many there may be.
- acescence0
so, in the context of what bort originally posted, it would look like:
<?php
$myImages = get_post_meta($post->ID, 'image', false);
if ($myImages) {
foreach($myimages as $image){ ?>
<img src="<?php echo $image; ?>" width="150" height="150" >
<?php }
} ?>
- forcetwelve0
thx again guys!