How to echo Wordpress/PHP functions with strings -


here 2 examples of i'm referring to.

if wanted make array containing images , echo out later, , have images refer home directory, following:

<?php  $get_directory = site_url(); $random = rand(0, 1); $picture = array(                 $get_directory.'/images/0.jpg',                 $get_directory.'/images/1.jpg',             );  ?> 

and call it:

<img src="<?php echo $picture[$random];?>"></a> 

i put site_url() in $get_directory variable , worked properly. before did that, tried inserting function directly array , didn't work.

another example found recently, involving echoing string:

<?php  $thumbnail = get_post_meta($post->id, $img, $single = true); $get_directory = site_url();      if (!$thumbnail) {         echo ''; } else {         echo '<img src="'.$get_directory.'/wp-content/uploads/'.$thumbnail.'">'; ?> 

i needed put home directory site_url() function , get_post_meta() function variables echo them out, put them in array, or concatenate them.

i'm wondering if correct way , if functions need placed variables, or if there's correct way it.

i apologize in advance if question inappropriate or has been asked , answered. looked , did not find exact question. i'm new programming aspect of web development. thank you.

site_url() takes parameter ($path). parameter appended site url:

echo '<img src="'.$get_directory.'/wp-content/uploads/'.$thumbnail.'">'; 

can become:

echo '<img src="' . site_url('/wp-content/uploads/' . $thumbnail) . '">'; 

so no: no need store result of site_url() in variable each time.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -