Help putting <?php ?> inside <?php xyz('here');?>

Discussion in 'PHP' started by Hades, Apr 21, 2008.

  1. #1
    Hi,

    I am coding a wordpress theme, and I am trying to do something that probably isn't allowed by normal means, so I am wondering if there is a way to go around it.

    I have a piece of code that calls for the content <?php the_content();?> and then a I have a code that states the directory of the stylesheet <?php bloginfo('stylesheet_directory'); ?> what I am trying to do is this:

    <?php the_content('<img src="<?php bloginfo('stylesheet_directory'); ?>/images/image.gif" alt="Read More.." />');?> but obviously the <?php bloginfo('stylesheet_directory'); ?> would not come out right in that code, so is there a way to put that <?php bloginfo('stylesheet_directory'); ?> into the <?php the content('here');?> in order to make it work?

    Regards,
    Nick
     
    Hades, Apr 21, 2008 IP
  2. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Make bloginfo return the stylesheet_directory, and then just go something like:

    <? the_content('<img src="' . blog_info('stylesheet_directory') . " . . . ?>

    and in function blog_info() make sure at the end it has return $stylesheet; or whatever it needs to be returning. I'm assuming this is a string?
     
    Louis11, Apr 21, 2008 IP
  3. Hades

    Hades Well-Known Member

    Messages:
    1,873
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    150
    #3
    I think it's a string. I don't really know php, I just know the php codes that are in wordpress.

    This is what I have:

    <?php the_content('<img src="<?php bloginfo('stylesheet_directory');?>/images/read-more.gif" alt="read more..." class="read-more" />'); ?>
    PHP:
    basicaly bloginfo('stylesheet_directory');?> calls for the directory of where the stylesheet is located, which is "wp-content/themes/theme-name/". I need to put that in there every time I use the <img src="" /> thing so that an image shows up. (Otherwise it looks in the base directory, and there is no such image there). But the way I have it now, it gives me an error, and I dont have enough php skills to know how it's supposed to be done, so wouldn't you mind showing me?

    Regards,
    Nick
     
    Hades, Apr 21, 2008 IP
  4. Accelerated Media

    Accelerated Media Banned

    Messages:
    597
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    
    $bloginfo = bloginfo('stylesheet_directory');
    
    the_content('<img src="' . $bloginfo . '/images/image.gif" alt="" />');
    
    ?>
    Code (markup):
    should work, no?
     
    Accelerated Media, Apr 21, 2008 IP
  5. Hades

    Hades Well-Known Member

    Messages:
    1,873
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    150
    #5

    Nop. That didn't work. It actually shows what the first part is and then doesn't recognize blogifno in the_content. Here is an html output:

    http://localhost/wordpress/wp-content/themes/themename<p>Hello<br />
    Hello<br />
    Hello<br />
    <a href="http://localhost/wordpress/?p=36#more-36" class="more-link"><img src="/images/read-more.gif" alt="" /></a></p>
     
    Hades, Apr 21, 2008 IP
  6. CPURules

    CPURules Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Based on what you posted up on the OP, this should work

    
    <?php
    the_content('<img src="' . bloginfo('stylesheet_directory') . '/images/image.gif" alt="Read More.." />'); 
    ?>
    
    PHP:
    If it doesn't work(and it's basically just a rewritten version of what Accelerated Media posted) then there's probably a problem with your bloginfo() function.
     
    CPURules, Apr 21, 2008 IP