2
I’m having trouble getting thumbnail (highlighted image) and permalink from the most recent post to be displayed on my blog home. I made the following code:
<?php
$posts_noticias = get_noticias_posts();
$destacado = array_shift($posts_noticias);
?>
<div id="noticia_destacada">
<a href="<?php the_permalink() ?>">
<?php the_post_thumbnail(array(495, 368, true)); ?>
<span class="data_noticia"><?php echo $destacado->post_date ?></span>
<h3 class="title_destacada"><?php echo $destacado->post_title ?></h3>
<?php echo $destacado->post_excerpt ?>
</a>
</div>
The code for the get_noticias_posts() function is as follows::
function get_noticias_posts($number = 5){
$args = array(
'posts_per_page' => $number,
'offset' => 0,
'category' => get_cat_ID( 'noticias' ),
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'suppress_filters' => true );
$posts_array = get_posts( $args );
return $posts_array;
}
However, the image displayed and the permalink I put in it are not from the last post but from an older post, from days ago. The date, title and excerpt from the most recent post appear normally.
I can’t figure out which part of the code I missed. Could you help me?
Should you not use the same instruction for thumbnail that you used for
post_date
andpost_title
guy:<?php echo $destacado->the_post_thumbnail(array(495, 368, true)); ?>
– Marcos Vinicius
@marcosvinicius Unfortunately gave fatal error here in my tests...
– Giancarlo Silva