wordpress - Common php function called by other functions -
hello create 2 functions different parameter same common function. here's example...
the common function :
function my_responsive_pictures($post_id){ // alt text or set $alt_text variable post title if no alt text exists $alt_text = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); if ( !$alt_text ) { $alt_text = esc_html( get_the_title($post_id) ); } // info each image size including original (full) $thumb_original = wp_get_attachment_image_src($attachment_id, 'slideshow'); $thumb_large = wp_get_attachment_image_src($attachment_id, 'slideshow-lg'); $thumb_medium = wp_get_attachment_image_src($attachment_id, 'slideshow-md'); $thumb_small = wp_get_attachment_image_src($attachment_id, 'slideshow-xs'); // create array containing each image size + alt tag $thumb_data = array( 'thumb_original' => $thumb_original[0], 'thumb_large' => $thumb_large[0], 'thumb_medium' => $thumb_medium[0], 'thumb_small' => $thumb_small[0], 'thumb_alt' => $alt_text ); // echo out <picture> element based on code above echo '<picture>'; echo '<!--[if ie 9]><video style="display: none;"><![endif]-->'; // fallback <video> element ie9 echo '<source srcset="' . $thumb_data['thumb_large'] . ', ' . $thumb_data['thumb_original'] . ' x2" media="(min-width: 800px)">'; echo '<source srcset="' . $thumb_data['thumb_medium'] . ', ' . $thumb_data['thumb_large'] . ' x2" media="(min-width: 400px)">'; echo '<source srcset="' . $thumb_data['thumb_small'] . ', ' . $thumb_data['thumb_medium'] . ' x2">'; echo '<!--[if ie 9]></video><![endif]-->'; // fallback <video> element ie9 echo '<img srcset="' . $thumb_data['thumb_small'] . ', ' . $thumb_data['thumb_medium'] . ' x2" alt="' . $thumb_data['thumb_alt'] . '">'; echo '</picture>'; }
another 1 calls common function :
function my_responsive_thumbnail($post_id){ // featured image id $attachment_id = get_post_thumbnail_id($post_id); my_responsive_pictures(); }
and second 1 other parameters $attachment_id :
function my_responsive_acfthumbnail($post_id){ // featured image id $attachment_id = get_field('image_bandeau'); my_responsive_pictures(); }
nothing happens :(. do wrong ? thanx help...
your function expecting parameter, , when you're calling here
my_responsive_pictures();
you aren't passing anything.
you have call my_responsive_thumbnail() function before it's going make subsequent calls "common" function.
Comments
Post a Comment