Hello Friend's in this post we are talking about how to get posts and feature images in your simple template pages because if you are a beginner definitely you are facing a problem to customize a simple template page so we are going to create some PHP loops to get a post, description, title, feature images and all .
Step-1. In this first step, we create a simple PHP array and while loop code.
<?php query_posts(array('post_type'=>'post', // this a array of post
'post_status'=>'publish',
'orderby' =>'menu-order',
'order' =>'DSC',
));
while ( have_posts() ) : the_post(); //this is a while loop of post
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<?php
end while; // end of the loop.
wp_reset_query();
?>
Step-2. In this second step, we are creating some PHP code to get the title of posts and put them the code in your html where you want to show title. One thing is highly recommended please write whole code inside the while loop.
<?php the_title(); ?> //this is title code
Step-3. In the third step, we are creating PHP code to get feature Image of posts and Description. The codes in your HTML where you want to show title. One thing is highly recommended please write whole code inside the while loop.
<?php echo $feat_image; ?> //this is freature image code
<?php the_excerpt();?> // this is description code
Step-4. In this fourth step, we are creating PHP URL code to get URL of any pages.
<?php the_permalink();?> // this is URL code
Step-5. In this step, we provide all code and show how to put PHP code in our HTML file inside the loop.
<?php query_posts(array('post_type'=>'post',
'post_status'=>'publish',
'orderby' =>'menu-order',
'order' =>'DSC',
));
while ( have_posts() ) : the_post();
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<li class="col-md-6">
<div class="img">
<img src="<?php echo $feat_image;?>"> //featureImage code
</div>
<div class="cont">
<?php the_excerpt();?>
<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2> // title code
<span class="hyp-link"><a href="<?php the_permalink();?>">Here's the full story ..... </a> </span> //URL Code
</div>
</li>
<?php
endwhile; // end of the loop.
wp_reset_query();
?>
0 comments:
Post a comment