I would like to add a link via custom post type so that an image appears based on the page template, but I can't seem开发者_Python百科 to show the link in between the img src, here is my php code for this:
<?php
$logoImg = print(get_post_meta($post->ID, 'Page Logo', true));
if ( is_page_template('second_page.php')) {
echo '<div class="middle-strip">' . '$logoImg' . '</div>';
}else{
echo '';
}
?>
- Assign the value to $logoImg directly, "print" returns an integer, not the value .
- Use double quotes, or No quotes to print the value of $logoImg . Single quotes will just print the string $logoImg , and not its value.
This code would work :
<?php
$logoImg = get_post_meta($post->ID, 'Page Logo', true);
if ( is_page_template('second_page.php')) {
echo '<div class="middle-strip">' . $logoImg . '</div>';
}else{
echo '';
}
?>
精彩评论