Error en php

raysn22 Seguir

Dseda
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
Desde
25 Feb 2016
Mensajes
1.176
Saludos, Estoy editando un theme y quite su imagen destacada para no subir imagenes al servidor y puse un custom fields para poner la imagen directa desde themoviedb
pero creando los post relacionados no puedo llamar la imagen ya que me tira el siguiente error en la linea 380 alguien puede decirme por que y gracias de ante mano

relacionadas.png

codigo relacionadas error.png
 

John Roronoa

Iota
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Desde
29 Oct 2019
Mensajes
2.186
Para la proxima escribe el codigo y no lo subas en imagen

concatena así:
<img class="thumb_rel" src="https://image.tmdb.org/t/p/w185/'.the_field('imagen_post_ty').'></img>

Y sobre el tag <img> no debe cerrarse asi </img>
debe cerrarse con />
Así:
<img class="thumb_rel" src="https://image.tmdb.org/t/p/w185/'.the_field('imagen_post_ty').' />
 

Stron

Eta
Diseñador
Verificación en dos pasos activada
Verificado por Whatsapp
Desde
11 Oct 2015
Mensajes
1.271
Estas poniendo etiquetas de apertura y cierre de php "<?php ?> " y el archivo functions ya tiene al principio la etiqueta de apertura, si quieres agregar html en el código, usa puntos para concatenar. '<im src=" '. the_field('imagen_post_ty') . '/>'
 

rocket

Gamma
Verificación en dos pasos desactivada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Desde
19 Feb 2015
Mensajes
207
Si tienes abierta la etiqueta de PHP <?php no debes volver a abrirla, te sugiero ordenes el código para ayudarte. Y recuerda que si vas a colocar código HTML en medio de etiquetas PHP debes usar echo.
Ejemplo:

<?php
echo <b>hola mundo</b>
?>
 

raysn22

Dseda
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
Desde
25 Feb 2016
Mensajes
1.176
Estas poniendo etiquetas de apertura y cierre de php "<?php ?> " y el archivo functions ya tiene al principio la etiqueta de apertura, si quieres agregar html en el código, usa puntos para concatenar. '<im src=" '. the_field('imagen_post_ty') . '/>'
Funciono pero me agarraba la imagen del post actual y no la de los relacionados
 

Stron

Eta
Diseñador
Verificación en dos pasos activada
Verificado por Whatsapp
Desde
11 Oct 2015
Mensajes
1.271
Funciono pero me agarraba la imagen del post actual y no la de los relacionados


Pon tu código completo de tu función aquí. Necesitas hacer un bucle de los posts, Revisa tu función y fijate si ya tiene un bucle (while o for) y pones dentro del bucle la imagen.

Ejemp:
PHP:
$args=array(
    'post_type' => 'post',
    'posts_per_page' => '20',
    'post_status' => 'publish',
    'order'=>'DESC',
    'orderby'=>'ID', 
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();

        $post_id = $post->ID;
       echo '<img class="thumb_rel" src="https://image.tmdb.org/t/p/w185/[/URL][B]'.the_field('imagen_post_ty',$post_id ).' />';
    }
    wp_reset_postdata();
}
 

raysn22

Dseda
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
Desde
25 Feb 2016
Mensajes
1.176
Pon tu código completo de tu función aquí. Necesitas hacer un bucle de los posts, Revisa tu función y fijate si ya tiene un bucle (while o for) y pones dentro del bucle la imagen.

Ejemp:
PHP:
$args=array(
    'post_type' => 'post',
    'posts_per_page' => '20',
    'post_status' => 'publish',
    'order'=>'DESC',
    'orderby'=>'ID',
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
    while ( $query->have_posts() ) {
        $query->the_post();

        $post_id = $post->ID;
       echo '<img class="thumb_rel" src="https://image.tmdb.org/t/p/w185/[/URL][B]'.the_field('imagen_post_ty',$post_id ).' />';
    }
    wp_reset_postdata();
}

Este fue el codigo que utilice para los post relacionados Lo unico que edite fue la parte de <a class="thumb_rel" href="{url}">{thumb}</a>
PHP:
<?php
 
 function dc_related_after_content( $content )
 {
    
    if ( !is_singular('post') ) return $content;   
    
    $cad            = "";
    $template_li     = '<li>
                            <a class="thumb_rel" href="{url}">{thumb}</a>
                            <a class="title_rel" href="{url}">{title}</a>
                        </li>';
    $template_rel    = '<div class="rel_posts">
                            <h3>Artículos Relacionados</h3>
                            <ul>
                                {list}
                            </ul>
                       </div>';

    $terms = get_the_terms( get_the_ID(), 'category');
    $categ = array();
    
    if ( $terms )
    {
        foreach ($terms as $term)
        {
            $categ[] = $term->term_id;
        }
    }
    else{
        return $content;
    }

    $loop    = new WP_QUERY(array(
                    'category__in'        => $categ,
                    'posts_per_page'    => 4,
                    'post__not_in'        =>array(get_the_ID()),
                    'orderby'            =>'rand'
                    ));

    if ( $loop->have_posts() )
    {

        while ( $loop->have_posts() )
        {
            $loop->the_post();

            $search     = Array('{url}','{thumb}','{title}');
              $replace = Array(get_permalink(),get_the_post_thumbnail(),get_the_title());
        
            $cad .= str_replace($search,$replace, $template_li);
        }

        if ( $cad )
        {
              $content .= str_replace('{list}', $cad, $template_rel);
        }

    }
       wp_reset_query();

    return $content;
}

add_filter( 'the_content', 'dc_related_after_content');
 

YeltsinReyes

Lambda
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
Desde
16 Feb 2010
Mensajes
2.939
@raysn22 puedes hacer lo mismo que haces con el titulo que lo renplazas, asi usas el fiel abajo en el loop
 

Stron

Eta
Diseñador
Verificación en dos pasos activada
Verificado por Whatsapp
Desde
11 Oct 2015
Mensajes
1.271
intenta esto, Reemplaza esto:
$replace = Array(get_permalink(),get_the_post_thumbnail(),get_the_title());
Por
PHP:
$img ='<img class="thumb_rel" src="https://image.tmdb.org/t/p/w185/'.the_field('imagen_post_ty',$post->ID).' />';
$replace = Array(get_permalink(),$img,get_the_title());
 

YeltsinReyes

Lambda
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
Desde
16 Feb 2010
Mensajes
2.939
o asi..

PHP:
<?php
 
function dc_related_after_content($content){
    
    if(!is_singular('post')) return $content;   
    
    $cad = '';
    
    $template_li = '<li>
        <a class="thumb_rel" href="{url}">
            <img class="thumb_rel" src="https://image.tmdb.org/t/p/w185/{thumb}"/>
        </a>
        <a class="title_rel" href="{url}">
            {title}
        </a>
    </li>';
    
    $template_rel = '<div class="rel_posts">
        <h3>Artículos Relacionados</h3>
        <ul>{list}</ul>
    </div>';

    $terms = get_the_terms(get_the_ID(), 'category');
    $categ = array();
    
    if($terms){
        foreach($terms as $term){
            $categ[] = $term->term_id;
        }
    } else {
        return $content;
    }

    $loop = new WP_QUERY(array(
        'category__in' => $categ,
        'posts_per_page' => 4,
        'post__not_in' =>array(get_the_ID()),
        'orderby' =>'rand'
    ));
    
    if($loop->have_posts()){

        while($loop->have_posts()){
            
            $loop->the_post();

            $search = Array('{url}', '{thumb}', '{title}');
            $replace = Array(get_permalink(), the_field('imagen_post_ty'), get_the_title());
            $cad .= str_replace($search, $replace, $template_li);
            
        }

        if($cad){
            $content .= str_replace('{list}', $cad, $template_rel);
        }

    }
    
    wp_reset_query();
    
    return $content;
    
}

add_filter( 'the_content', 'dc_related_after_content');
 

raysn22

Dseda
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
Desde
25 Feb 2016
Mensajes
1.176
o asi..

PHP:
<?php

function dc_related_after_content($content){
   
    if(!is_singular('post')) return $content;  
   
    $cad = '';
   
    $template_li = '<li>
        <a class="thumb_rel" href="{url}">
            <img class="thumb_rel" src="https://image.tmdb.org/t/p/w185/{thumb}"/>
        </a>
        <a class="title_rel" href="{url}">
            {title}
        </a>
    </li>';
   
    $template_rel = '<div class="rel_posts">
        <h3>Artículos Relacionados</h3>
        <ul>{list}</ul>
    </div>';

    $terms = get_the_terms(get_the_ID(), 'category');
    $categ = array();
   
    if($terms){
        foreach($terms as $term){
            $categ[] = $term->term_id;
        }
    } else {
        return $content;
    }

    $loop = new WP_QUERY(array(
        'category__in' => $categ,
        'posts_per_page' => 4,
        'post__not_in' =>array(get_the_ID()),
        'orderby' =>'rand'
    ));
   
    if($loop->have_posts()){

        while($loop->have_posts()){
           
            $loop->the_post();

            $search = Array('{url}', '{thumb}', '{title}');
            $replace = Array(get_permalink(), the_field('imagen_post_ty'), get_the_title());
            $cad .= str_replace($search, $replace, $template_li);
           
        }

        if($cad){
            $content .= str_replace('{list}', $cad, $template_rel);
        }

    }
   
    wp_reset_query();
   
    return $content;
   
}

add_filter( 'the_content', 'dc_related_after_content');
Funciono en vez de poner the_field puse get_field y tomo las imagenes correctas, Muchas gracias a todos por su ayuda
 

¡Regístrate y comienza a ganar!

Beneficios

  • Gana dinero por participar
  • Gana dinero por recomendarnos
  • Descubre ofertas de empleo diariamente
  • Negocios seguros
  • ¡Información premium y más!

Acceder

¿Ya tienes una cuenta? Accede aquí

Arriba