Asaf Biton
Asaf Biton

Reputation: 177

Using tags and php codes together under an echo

Hi I tried to echo a image (as a part of an if/else code), but I couldn't really do it.

Here's my code:

echo "<a href="<?php the_permalink() ?>" rel="bookmark" ><img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo get_post_meta( $post->ID, 'image_value', true ); ?>&amp;w=225&amp;h=246&amp;zc=1" alt="<?php the_title(); ?>" /></a>";

As you can see its obviously because of the " and '. The tags attributes (by attributes I mean 'alt' 'src' etc..) require a " while the php tags only work with ' .. so I didn't really know what to do hehe..

Any suggestions?

By the way, the CMS is wordpres. If it helps..

Upvotes: 0

Views: 244

Answers (3)

Will
Will

Reputation: 1619

The issue is Wordpress functions like the_permalink and bloginfo use the echo function as well, so it doesn't work when you try to put the two together. They don't return anything. Instead, you want to use the functions that will return a string, so you can concatenate the return values with the HTML you want to output.

Try this:

echo "<a href='" . get_permalink() . "' rel='bookmark'><img src='" . get_bloginfo('template_directory') . "'/timthumb.php?src=";

You can fill in the rest.

Note: be wary of the rest of the answers. They appear to be answering the root of your question, but they ignore the nuances of the wordpress functions.

Upvotes: 1

Mikhail
Mikhail

Reputation: 9007

Check out PHP's strings and how to concatenate them

Upvotes: 1

RiaD
RiaD

Reputation: 47620

echo '<a href="'.the_permalink().'" rel="bookmark" ><img src="'.bloginfo( 'template_directory' ).'/timthumb.php?src='.get_post_meta( $post->ID, 'image_value', true ) .'&amp;w=225&amp;h=246&amp;zc=1" alt="'.the_title().'" /></a>';

Upvotes: -1

Related Questions