こんにちは私は異なるパラメータを持つが同じ共通関数を持つ2つの関数を作成したいと思います。ここに私の例です...他の関数から呼び出される一般的なphp関数
共通機能:
function my_responsive_pictures($post_id){
// Get alt text or set the $alt_text variable to the 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)); }
// Get the info for each image size including the 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 + the 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 from above
echo '<picture>';
echo '<!--[if IE 9]><video style="display: none;"><![endif]-->'; // Fallback to <video> element for 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 to <video> element for IE9
echo '<img srcset="' . $thumb_data['thumb_small'] . ', ' . $thumb_data['thumb_medium'] . ' x2" alt="' . $thumb_data['thumb_alt'] . '">';
echo '</picture>';
}
共通関数を呼び出すもう1:
function my_responsive_thumbnail($post_id){
// Get the featured image ID
$attachment_id = get_post_thumbnail_id($post_id);
my_responsive_pictures();
}
及びその他のパラメータ$ attachment_IDを有する第二1:
function my_responsive_acfthumbnail($post_id){
// Get the featured image ID
$attachment_id = get_field('image_bandeau');
my_responsive_pictures();
}
を
何も起こりません:(何が間違っていますか?Thanx、あなたの助けに...
機能は、同じファイル内にありますか?あなたは必要なパラメータも逃してしまいます。 – stuzzo