WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Help with php bloginfo('template_directory'); (11 posts)

  1. TechInfo2
    Member
    Posted 5 years ago #

    <?php
    	$thumb = get_post_meta($post->ID,'Thumbnail', true);
    	$thumb = ( !empty( $thumb ) ) ? $thumb : '/images/whitebg.jpg';
    	print '<img src="' . $thumb . '" width="80" height="80" alt="" />';
    	?>

    I'm doing a Theme, but I can't link to the image theme folder like this: <?php bloginfo('template_directory'); ?>/images/whitebg.jpg
    is there any other way to do that?
    Thanks

  2. TechInfo2
    Member
    Posted 5 years ago #

    Please I really need your Help

  3. Try get_bloginfo('stylesheet_directory'); instead and see if that works better for you.

  4. stvwlf
    Member
    Posted 5 years ago #

    The problem is bloginfo is echoing the output
    Use this function instead http://codex.wordpress.org/Template_Tags/get_bloginfo

  5. TechInfo2
    Member
    Posted 5 years ago #

    <?php
    	$thumb = get_post_meta($post->ID,'Thumbnail', true);
    	$thumb = ( !empty( $thumb ) ) ? $thumb : '<?php get_bloginfo('stylesheet_directory');?>/images/whitebg.jpg';
    	print '<img src="' . $thumb . '" width="80" height="80" alt="" />';
    	?>

    jdembowski thanks for your Answer but I have tried, does not work
    If I view the image, I get the web address URL like this: http://localhost/wordpress/%3C?php%20get_bloginfo(%27stylesheet_directory%27);%20?%3E/images/whitebg.jpg ;)

  6. Mark / t31os
    Moderator
    Posted 5 years ago #

    Like stvwlf said, use get_bloginfo() INSTEAD of bloginfo()...

    get_bloginfo DOES NOT echo, unlike bloginfo....

  7. TechInfo2
    Member
    Posted 5 years ago #

    Ok Thank you everyone, but I have solved my own problem ;)

    here is the Problem

    <?php
    	$thumb = get_post_meta($post->ID,'Thumbnail', true);
    	$thumb = ( !empty( $thumb ) ) ? $thumb : '<?php get_bloginfo('stylesheet_directory');?>/images/whitebg.jpg';
    	print '<img src="' . $thumb . '" width="80" height="80" alt="" />';
    	?>

    here is the Problem solved.

    <?php
    	$thumb = get_post_meta($post->ID,'Thumbnail', true);
    	$thumb = ( !empty( $thumb ) ) ? $thumb : './wp-content/themes/mytheme/images/whitebg.jpg';
    	print '<img src="' . $thumb . '" width="80" height="80" alt="" />';
    	?>

    Thank you everyone and Good night

  8. Mark / t31os
    Moderator
    Posted 5 years ago #

    Hi, the problem was this line..

    $thumb = ( !empty( $thumb ) ) ? $thumb : '<?php get_bloginfo('stylesheet_directory');?>/images/whitebg.jpg';

    Which should be..

    $thumb = ( !empty( $thumb ) ) ? $thumb : get_bloginfo('stylesheet_directory').'/images/whitebg.jpg';

    Due to the second <?php ....

    Incorrectly switching in/out of PHP...

    I skimmed over the post before because the solution was already given.

  9. TechInfo2
    Member
    Posted 5 years ago #

    Thanks t31os
    I have change instead of this get_bloginfo('stylesheet_directory') to
    get_bloginfo('template_directory')

    like this:

    <?php
    	$thumb = get_post_meta($post->ID,'Thumbnail', true);
    	$thumb = ( !empty( $thumb ) ) ? $thumb : get_bloginfo('template_directory').'./images/whitebg.jpg';
    	print '<img src="' . $thumb . '" width="80" height="80" alt="Post Thumb" />';
    	?>

    and It works great! ;)

  10. Mark / t31os
    Moderator
    Posted 5 years ago #

    Yep, just use whichever works for you... :)

    http://codex.wordpress.org/Template_Tags/get_bloginfo

    ;)

  11. bourkela
    Member
    Posted 4 years ago #

    Thanks for the get_bloginfo tip!

Topic Closed

This topic has been closed to new replies.

About this Topic