Last active
April 2, 2020 15:36
-
-
Save prosantamazumder/a68008e9dd706322bf929048e0b8d352 to your computer and use it in GitHub Desktop.
WordPress Custom Page Template Post Query Loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
get_header(); | |
/* | |
Template Name: pagename | |
*/ | |
?> | |
<?php | |
$loop = new WP_Query( array( | |
'post_type' => 'promotion', //CUSTOM POST NAME | |
'posts_per_page' => -1, // SHOE POST PER PAGE | |
'orderby' => 'title', | |
'order' => 'ASC', //DSC | |
) | |
); | |
?> | |
<div class="pagetemplate-area"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<div class="single-post"> | |
<?php if ( $loop->have_posts() ) : | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
$thumbnails = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full'); | |
$content = get_the_content(); | |
?> | |
<!-- HTML CODE SINGLE POST LOOP --> | |
<div class="row"> | |
<a href="#"> | |
<img src="<?php echo $thumbnails[0]; ?>" alt="<?php the_title(); ?>" /> | |
</a> | |
</div> | |
<!-- END HTML CODE SINGLE POST LOOP --> | |
<?php endwhile; wp_reset_query(); ?> | |
<?php else : //ECHO POST NOT FOUND ?> | |
<p class="text-center" style="color: red; font-weight: bold;"><?php esc_html_e( 'Sorry, No Post matched your criteria. Please Add New Post Thank You..!' ); ?></p> | |
<?php endif; ?> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment