<?php $the_query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1, 'post_status' => array( 'publish' ), ) ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); ?> <div class="container"> <article id="post-<?php the_ID(); ?>" <?php post_class('blog-item'); ?>> <div class="blog-item__info"> <div class="blog-item__author"> <?php if (get_field('single_author')) { ?> <?php echo get_field('single_author'); ?> <?php } else { ?> <?php the_author(); ?> <?php } ?> </div> <div class="blog-item__date"> <?php the_date('F j, Y'); ?> </div> </div> <div class="blog-item__category"> <?php $categories = get_the_category(); if ( ! empty( $categories ) ) { foreach( $categories as $category ) { ?> <a href="<?php echo esc_url( get_category_link( $category->term_id ) )?>"> <?php echo esc_html( $category->name );?> </a> <?php } } ?> </div> <h2 class="blog-item__title"> <a href="<?php the_permalink(); ?>" class="link link--underline-left link link--underline-left--invert"> <?php the_title(); ?> </a> </h2> <div class="blog-item__thumb"> <a href="<?php the_permalink(); ?>"> <?php if (has_post_thumbnail() ): ?> <?php the_post_thumbnail(); ?> <?php endif; ?> </a> </div> <?php if (has_excerpt()) { ?> <div class="blog-item__excerpt"> <?php the_excerpt(); ?> </div> <?php } ?> <div class="blog-item__more"> <div class="btn-round-invert"> <a href="<?php the_permalink(); ?>"> <?php _e('Read more', 'theme'); ?> </a> </div> </div> </article> </div> <?php } } else { // no posts found } /* Restore original Post Data */ wp_reset_postdata(); ?>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter