HTML to WordPress
How to General Post Query in WordPress
Welcome to all in “How to General Post Query in WordPress” tune. Today I am going to simply describe about WordPress post query. This an important thing in WordPress but very easy.
<?php if(have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <!-- Your Post Query HTML goes here --> <?php endwhile; ?> <?php endif; ?>
If you think this code deeply this is very simple PHP code. Only two PHP code start and those two PHP code end. In the middle of this PHP code will be you a single post HTML code. To understand easily a simple HTML code given below.
<div class="single_post"> <h2><a href="#">Here is post title</a></h2> <div class="post_info"> Posted In: Post Category | Posted on: Posted date 1 Comment </div> <div class="post_content"> <a href="#"><img src="image location"></a> I have a vegan cooking show that I have been on , in the USA. I have been doing that show for 3 years now and would like to do something similar here in the UK. I have a vegan cooking show that I have been on , in the USA. I have been doing that show for 3 years now and would like to do something similar here in the UK. I have a vegan cooking show that I have been on , in the USA. I have been doing that show for 3 years now and would like to do something similar here in the UK. </div> </div>
On this HTML need to use some PHP for getting dynamically post title, permalink, content, author, date, category etc. Some PHP code given below:
<?php the_title(); ?> = Use this for dynamic post title. <?php the_permalink(); ?> = Use this for dynamic post permalink. <?php the_time('M d, Y') ?> = Use this for dynamic posted date. <?php the_excerpt(); ?> = Use this for post excerpt. <?php the_content(); ?> = Use this for dynamic full post content. <?php the_category(', '); ?> = Use this for dynamic posted category. <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?> = Use this for get post comment.
Finally your query will be look like this code:
<?php if(have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="single_post"> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="post_info"> Posted In: <?php the_category(', '); ?> | Posted on: <?php the_time('M d, Y') ?> <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?> </div> <div class="post_content"> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('post-image', array('class' => 'post-thumb')); ?></a> <?php echo excerpt('60'); ?> </div> </div> <?php endwhile; ?> <?php endif; ?>
Thanks all. If face any problem comment here.
Comments are closed