Display new and old posts on wordpress pages

Asked

Viewed 90 times

0

Good morning, I’m needing to display my wordpress news with footer links to old and new posts. I am using bootstrap as a template for my website and am with the following code for the display layout of these new and old posts:

<div class="card" style="width: 18rem;">
  <img class="card-img-top" src="https://via.placeholder.com/286px180/" alt="Card image cap">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

Would you like to know how I can do that? If anyone can help me please thank you, for my head is at stake in this.

1 answer

0


<?php

$args = array(
    'numberposts' => 5, //numero de posts que vai exibir
    'orderby' => 'post_date',
    'order' => 'DESC',
    'post_type' => 'post',
    'post_status' => 'publish',
);
$query = new WP_Query( $args );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) : $query->the_post();
?>

  <div class="card" style="width: 18rem;">
    <img class="card-img-top" src="<?php the_post_thumbnail_url( 'thumbnail' ); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
    <div class="card-body">
      <h5 class="card-title"><?php the_title(); ?></h5>
      <p class="card-text"><?php the_excerpt(); ?></p>
      <a href="<?php the_permalink(); ?>" class="btn btn-primary">Go somewhere</a>
    </div>
  </div>

<?php 
  endwhile; 
  wp_reset_postdata();
endif;
  • It worked right here Lucas. Thank you very much msm! You saved my life.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.