another wordpress Q
- Started
- Last post
- 7 Responses
- forcetwelve
is it possible to have a custom field image act as a link?
the reason for this is i have feature images on my homepage that i would like to link to pages - as i don't use posts.
does this make sense?
- Amicus0
Sorry, I don't know the answer to this question, but how the hell are ya Adam?
- mydo0
you can have your custom field as HTML, and just include your image and link on this.
OR have another customer field for your URL.and probably a few other options!
- forcetwelve0
do you mean have html in the actual c.field value field?
- acescence0
yes, you can use html as the custom field value.
or, since the images are associated with pages, you could give each page the custom field that is the image, then use get_pages on the homepage to grab all of the pages that have that custom field, which would also give you the links to those pages.
- forcetwelve0
so like this in my value?
<a href="linktomypage.html"><img src="http://website.com.au/test/wp-content/uploads/2010/02/box2.jpg"></a>
- forcetwelve0
hmm. no love. anyone care to take a look at my php?
<?php
/*
Template Name: Home Page
*/
?><?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?><div id="content">
<div id="feature"><?php wp_cycle(); ?></div>
<div id="line_full"></div>
<div id="intro">
<h3><?php echo get_post_meta($post->ID, 'intro_head', true); ?></h3>
<p><?php echo get_post_meta($post->ID, 'intro', true); ?></p>
</div><div id="boxes">
<div id="box1">
<?php
$myimages = get_post_meta($post->ID, 'feature1', false);
if ($myimages) {
foreach($myimages as $image){ ?>
<img src="<?php echo $image; ?>
<?php }
} ?>
<h3><?php echo get_post_meta($post->ID, 'feature1_header', true); ?></h3>
</div><div id="box2">
<?php if (get_post_meta($post->ID, 'feature2', true) ) { ?>
<img src="<?php echo get_post_meta($post->ID, 'feature2', true); ?>" width="190" height="110" >
<?php } ?>
<h3><?php echo get_post_meta($post->ID, 'feature2_header', true); ?></h3>
</div></div>
<?php endwhile; else: ?>
<?php endif; ?>
<div class="clearfooter"></div>
</div>
<?php get_footer(); ?>
- mydo0
i've not really looked at this properly. but i'm guessing $image; is the output from your custom field?
if so, you can just remove the image tag around it.or if it's box2,
change this
<img src="<?php echo get_post_meta($post->ID, 'feature2', true); ?>" width="190" height="110" >to this
<?php echo get_post_meta($post->ID, 'feature2', true); ?>
- and have the HTML in your custom. it's not ideal though.mydo
- legend! that fixed it. thx so much mate.forcetwelve
- no wurries mate.mydo