Erro em php

  • Autor Autor r0y
  • Data de início Data de início
Tradução em andamento: em alguns minutos este tópico estará em português. Por enquanto, o conteúdo está no original em espanhol. Ver original
r0y

r0y

Dseda
Verificación en dos pasos activada
Verificado por Binance
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.webp
 
Foi útil? Participe da conversa

Com sua conta grátis você pode responder, mandar mensagem privada ao autor e comprar com Saldo retido: o pagamento é liberado quando você recebe o combinado.

Leva 30 segundos · você volta a este tópico ao terminar
Quita <\img>
 
Nada sigue el error, el error me dice que esta en el custom fields en mas comillas simples cuando pongo dos comillas se quita el error pero no me llama el custom fields
 
Nada sigue el error, el error me dice que esta en el custom fields en mas comillas simples cuando pongo dos comillas se quita el error pero no me llama el custom fields

elimina <?php y ;?> y concatena!
 
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') . '/>'
 
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>
?>
 
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
 
Funciono pero me agarraba la imagen del post actual y no la de los relacionados

Entonce tienes que ver en que loop estas metiendo esa funcion!
 
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();
}
 
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');
 
@raysn22 puedes hacer lo mismo que haces con el titulo que lo renplazas, asi usas el fiel abajo en el loop
 
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());
 
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');
 
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
 
Voltar
Topo