r0y
Dseda
Verificación en dos pasos activada
Verificado por Whatsapp
Verificado por Binance
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 fieldsQuita <\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
Funciono pero me agarraba la imagen del post actual y no la de los relacionadosEstas 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
$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(); }
<?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');
Por$replace = Array(get_permalink(),get_the_post_thumbnail(),get_the_title());
$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());
<?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 ayudao 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');
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?
Utilizamos cookies y tecnologías similares para los siguientes fines:
¿Aceptas las cookies y estas tecnologías?