Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have include PHP-Code inside a href-tag – and it doesn’t work!

<?php $image = get_post_meta($post->ID, 'image_medium', true);
    if ( $image != '' ) {?> 

            <a href="<?php wp_get_attachment_image($image, 'category-large-thumb' ); ?>"  rel="enlargeimage" rev="targetdiv:loadarea,trigger:mouseover"><?php echo wp_get_attachment_image($image, 'category-small-thumb'); ?></a>

            <?php } ?>

The source code shows an empty href (href=““)

I checked it with a “direct” pathway (href=”/img.jpg”), like below, and it works

<?php $image = get_post_meta($post->ID, 'image2_medium', true);
    if ( $image != '' ) {?> 
        <a class="fancybox" href="<?php bloginfo('template_directory');?>/1_b.jpg" rel="enlargeimage" rev="targetdiv:loadarea,trigger:mouseover"><img src="<?php bloginfo('template_directory');?>/1_s.jpg" /></a>
    <?php } ?>

Where is my fault? How can I integrate the (loop-) php-code into the href-tag? Thanks Petra

share|improve this question

1 Answer 1

You're using a get function, which does not echo by default. Update the PHP portion to the following:

<?php echo wp_get_attachment_image($image, 'category-large-thumb' ); ?>

Also, wp_get_attachment_image() returns a full image object - so I don't think that's what your after.

It also most seems like you'd just want the_attachment_link:

<?php the_attachment_link( $id, $fullsize, $deprecated, $permalink ); ?>

So - it'd turn into:

<?php the_attachment_link(get_post_meta($post->ID, 'image_medium', true)); ?>
share|improve this answer
    
Thanks for the solutions – but it didn’t work inside a href-construct. I want to show small Images on one side, and by hovering shown larger image version shown beside that (and by click on the large image, fancybox open) (something like this danidraws.com ) With thumbnailviewer2 and Fancybox it works without php-code or with direct image pathway. my questions: - is where a chance to integrate php-code into href thats include custom post type variables and thumbnailviewer2 options - or is there an other way, to create these preview pictures –  Petra Oct 2 '12 at 11:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.