Un usuario pregunt贸 馃憞
Tengo una funci贸n en la plantilla single.php que muestra el valor del campo personalizado en iframe. Quiero convertirlo en un atajo, este es el tempalte …
<script type="text/javascript">
jQuery(document).ready(function($) {
$('iframe').each(function() {
if ( $(this).attr('src')=='') {
$(this).parent('.video-embed').hide();
}
});
});
</script>
<div id="video-embeds" style="z-index:102">
<div class="video-embed" style="margin-top: 0px; z-index:102; margin-bottom: 0px;">
<?php
$url1 = get_post_meta( $post->ID , 'video_play' , true );
$search = '#(.*?)(?:href="https?://)?(?:www.)?(?:youtu.be/|youtube.com(?:/embed/|/v/|/watch?.*?v=))([w-]{10,12}).*#x';
$replace = 'http://www.youtube.com/embed/$2';
$url2 = preg_replace($search,$replace,$url1);
$url3 = '<iframe width="560" height="315" src="'.$url2.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
$url4 = preg_match('~iframe.*src="([^"]*)"~', $url3, $result);
$url4 = $result[1];
?>
<iframe width="560" height="315" src="<?php echo $url4; ?>" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div></div>
Y tengo que ponerlo en algo como (s茅 que est谩 roto) …
function video_display( $atts, $content = null ) {
<script type="text/javascript">
jQuery(document).ready(function($) {
$('iframe').each(function() {
if ( $(this).attr('src')=='') {
$(this).parent('.video-embed').hide();
}
});
});
</script>
$url1 = get_post_meta( $post->ID , 'video_play' , true );
$search = '#(.*?)(?:href="https?://)?(?:www.)?(?:youtu.be/|youtube.com(?:/embed/|/v/|/watch?.*?v=))([w-]{10,12}).*#x';
$replace = 'http://www.youtube.com/embed/$2';
$url2 = preg_replace($search,$replace,$url1);
$url3 = '<iframe width="560" height="315" src="'.$url2.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
$url4 = preg_match('~iframe.*src="([^"]*)"~', $url3, $result);
$url5 = echo $result[1];
return '<div id="video-embeds" style="z-index:102">
<div class="video-embed" style="margin-top: 0px; z-index:102; margin-bottom: 0px;">
<iframe width="560" height="315" src="<?php echo $url4; ?>" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div></div>';
}
add_shortcode( 'video_display', 'video_display' );
Este tema fue modificado hace 2 a帽os, 4 meses por.
(@sterndata)
Moderador del foro y voluntario del equipo de apoyo
Hace 2 a帽os, 4 meses
Los atajos de eco no pueden hacer ni generar nada directamente, por lo que debe completar toda esa salida en una cadena y devolverla.
(@mllapan)
Hace 2 a帽os, 4 meses
Gracias.
Es algo como esto
function video_display( $atts, $content = null ) {
<script type="text/javascript">
jQuery(document).ready(function($) {
$('iframe').each(function() {
if ( $(this).attr('src')=='') {
$(this).parent('.video-embed').hide();
}
});
});
</script>
$url1 = 'https://www.youtube.com/watch?v=cWLPt4A5LJY';
$search = '#(.*?)(?:href="https?://)?(?:www.)?(?:youtu.be/|youtube.com(?:/embed/|/v/|/watch?.*?v=))([w-]{10,12}).*#x';
$replace = 'http://www.youtube.com/embed/$2';
$url2 = preg_replace($search,$replace,$url1);
$url3 = '<iframe width="560" height="315" src="'.$url2.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
$url4 = preg_match('~iframe.*src="([^"]*)"~', $url3, $result);
$url5 = $result[1];
$output .= '<div id="video-embeds" style="z-index:102">';
$output .= '<div class="video-embed" style="margin-top: 0px; z-index:102; margin-bottom: 0px;">';
$output .= '<iframe width="560" height="315" src="';
$output .= $url5;
$output .= '" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
$output .= '</div>';
$output .= '</div>';
return $output;
add_shortcode( 'video_display', 'video_display' );
Tambi茅n prob茅 esto con o sin javascript, y no funcionar谩, devolviendo un src desconocido sin javascript, con una p谩gina de javascript rota. Entonces, 驴d贸nde aplico javascript y c贸mo configurar esta parte $ salida? = $ Url5; como es obvio
Esta respuesta fue modificada hace 2 a帽os, 4 meses por. Esta respuesta fue modificada hace 2 a帽os, 4 meses por.
(@sterndata)
Moderador del foro y voluntario del equipo de apoyo
Hace 2 a帽os, 4 meses
M谩s o menos, s铆. Deber谩 pegar el javascript por separado, ya que creo que es demasiado lento si se permite en el contenido de la p谩gina.
Para transferir un valor de PHP a JS, usar铆a wp_localize_script () antes de asegurar el script en s铆. Esto crear谩 el bloque CDATA.
(@mllapan)
Hace 2 a帽os, 4 meses
Gracias por tu ayuda. Si solo tiene poco tiempo para anotar mi c贸digo, porque elimin茅 javascript y lo us茅 como una declaraci贸n. Esto es lo que encontr茅:
function video_display ($params, $content = null){
$url1 = get_post_meta(get_the_id(), 'video_play', true);
if( empty( $url1 ) ) {
return;
}
else {
$search = '#(.*?)(?:href="https?://)?(?:www.)?(?:youtu.be/|youtube.com(?:/embed/|/v/|/watch?.*?v=))([w-]{10,12}).*#x';
$replace = 'http://www.youtube.com/embed/$2';
$url2 = preg_replace($search,$replace,$url1);
$url3 = '<iframe width="560" height="315" src="'.$url2.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
$url4 = preg_match('~iframe.*src="([^"]*)"~', $url3, $result);
$url5 = $result[1];
$output .= '<div id="video-embeds" style="z-index:102">';
$output .= '<div class="video-embed" style="margin-top: 0px; z-index:102; margin-bottom: 0px;">';
$output .= '<iframe width="560" height="315" src="';
$output .= $url5;
$output .= '" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
$output .= '</div>';
$output .= '</div>';
return $output;
}
}
add_shortcode('video_display', 'video_display' );
驴Todo el c贸digo de amor?
(@sterndata)
Moderador del foro y voluntario del equipo de apoyo
Hace 2 a帽os, 4 meses
Lo siento, no tengo tiempo para probar tu c贸digo. Te recomiendo que pruebes la depuraci贸n habilitada.
驴Solucion贸 tu problema??
0 / 0