SoftwareQuery
Home About Contact

How To Get WordPress Posts and featured Image in the Template page

 SoftwareQuery     No comments   


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();
              ?>
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

0 comments:

Post a comment

Donate

Translate

Popular Posts

  • How to Make Image Upload Code Using AJAX
    Direct Copy Paste PHP File  Image Upload Code -   <html> <head> <meta charset="utf-8"> <meta http-equi...
  • Best Useful Free Plugin to Make Wordpress Theme
    Meta Slider   - Meta Slider is that the initial free possibility on today’s list. A premium version is additionally obtainable...
  • How To Install Magento on Localhost XAMPP OR WAMP SERVER
      Step-1 => Make Sure you have to install Latest Version of  Xampp server or Wamp server in your PC.   Step -2 => Go to Web Bro...
  • How To Intall Node.js Via Command On Window And Linux.
    Step-1 . Firstly We have to go official website of https://nodejs.org/en/ then download the latest version of Nodejs zi...
  • How to Set up Amazon Affiliate Marketing Account to Earn Money
    Amazon Associates is a  marketing of Amazon company. It is allowed to youtube channel owner, Social Media pages owner and any type...
  • How To Create Custom Pagination In WordPress
    Hello, Friend's in this post we are creating a custom code of Pagination in WordPress. It is very easy to put this code any custom...
  • How To Scrape Data From Website Url Using Php.
    Q. why using a Scraping. If we want to get data of another website then using web scraping. It is using a PHP HTML Dom parser library ...
  • How To Install Wordpress in Xampp Server And Wamp Server
      Step 1st  -      Install WampServer or Xampp Server.                                                                               ...
  • How to create facebook share and like button for webpage
    Step-1 . Go to web browser type google and write facebook sharing button click this URL or open this URL.                     Ref URL:...
  • How to create Database Connection with ENCRYPT Password in Php
    <?php  $username = $_POST['username'];   $email = $_POST['email'];  $psw = password_hash($_POST['psw'], PA...

Home

This blog Is very help full for beginner coder,if you want to learn new things definitely this Blog is very
helpful for you guys.

Followers

Contact form

Name

Email *

Message *

Blog

  • Home
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
  • Terms&Conditions

NewsLetter

Copyright © SoftwareQuery | Powered by softwarequery
Design by ShubhamTiwari | Theme by softwarequery.com | Distributed By softwarequery/