Add a post date to your custom wordpress post listing

this is an example using:
get_the_date: this one gets the post date
the_excerpt: which gets the .. excerpt or summary text from the post
get_the_post_thumbnail_url which gets the image from the post to use as the background of the div.


// the query
$wpb_all_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>-1)); ?>

<?php if ( $wpb_all_query->have_posts() ) : ?>

<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
    $thumbx = get_the_post_thumbnail('medium');
    $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'large');
    //  the_post_thumbnail - shows the image tag
    //  get_the_post_thumbnail - to a variable
    //  get_the_post_thumbnail_url - to the image url
  } else {
    $thumbx = "";
    $featured_img_url = "";

  <div class='large-4 cell'>
    <div class='the-post' style='background:linear-gradient( rgba(23, 58, 103, 0.6), rgba(23, 58, 103, 0.6) ),url(<?php echo $featured_img_url; ?>) center no-repeat; background-size:cover;'>
    <div class='the-post-title'><h3><a href="<?php the_permalink(); ?>" style='color: #ef5b00;'><?php the_title(); ?></a></h3></div>
    <div class='the-post-pub-date'><?php echo get_the_date(); ?></div>
    <div class='the-post-excerpt'><?php echo the_excerpt(); ?></div>
<?php endwhile; ?>
<!-- end of the loop -->

<?php wp_reset_postdata(); ?>

<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

Page Views

This page has been viewed 213 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
All of humanity's problems stem from man's inability to sit quietly in a room alone, wrote Blaise Pascal.