View new and old posts on wordpress pages

0

Good morning, I need to display my wordpress news with links in the footer for old and new posts. I'm using the bootstrap as a template for my site and I'm 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 this? If anyone can help me please thank you, because my head is at stake in this.

    
asked by anonymous 02.10.2018 / 15:55

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;
    
02.10.2018 / 19:27