WordPress.org

Ready to get started?Download WordPress

Forums

Global Content Blocks
[resolved] content block with php variables included in html (5 posts)

  1. vineela.s
    Member
    Posted 1 year ago #

    hi i have content block with shortcode [contentblock id=2];

    and the content in this global block is
    $themepath = "http://localhost/shriram/wp-content/themes/twentyeleven-child/images";
    <div class="bottomSlider"><img src="$themepath/shriram-home-finel_39.jpg" /></div>

    i am printing my content block in template file like this

    <?php echo do_shortcode('[contentblock id="2"]');?>

    and the output is so strange below is the output

    $themepath = "http://localhost/shriram/wp-content/themes/twentyeleven-child/images";
    <div class="bottomSlider"><img src="$themepath/shriram-home-finel_39.jpg" /></div>

    how can i use php variables in between html content and wht is the type of content i should select while creating content block?please help me on this...

    http://wordpress.org/extend/plugins/global-content-blocks/

  2. benz1
    Member
    Plugin Author

    Posted 1 year ago #

    You should use the PHP Code type, but be aware that the code will be interpreted by the PHP parser so should be written like this:

    $themepath = "http://localhost/shriram/wp-content/themes/twentyeleven-child/images";
    
    echo '<div class="bottomSlider"><img src="'.$themepath.'/shriram-home-finel_39.jpg" /></div>';

    or similar.

    Also, make sure you use the HTML tab of the editor when adding the code as the Visual tab will transform all tags into html safe entities which will raise an parser error if placed in a php content block.

  3. vineela.s
    Member
    Posted 1 year ago #

    I have tried your solution

    $themepath = bloginfo('stylesheet_directory');
    echo '<div class="bottomSlider"><img src="'.$themepath.'/images/sliderImg.jpg" /></div>';

    and the ouput is
    http://localhost/shriram/wp-content/themes/twentyeleven-child<div class="bottomSlider"><img src="/images/sliderImg.jpg"></div>

    themepath is printing above the div not inside image tag....

    help me on this .

  4. benz1
    Member
    Plugin Author

    Posted 1 year ago #

    You need to use the function 'get_bloginfo' instead of 'bloginfo' which directly echoes the result.

    I'm sorry but this is nothing to do with the plugin so I really can't healp you any further with this.

  5. vineela.s
    Member
    Posted 1 year ago #

    hi it is working like charm thank u so much for ur help :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic