SOME IMPORTANT PHP CODE FOR WORDPRESS

5:00:00 PM | ,

Are you creating own wordpress theme and searching php code for your theme like category, author, comments and archives here are some codes for you so you can create your template more wonderfull. Some parts of the WordPress code structure for PHP markup are inconsistent in their style. WordPress is working to gradually improve this by helping users maintain a consistent style so the code can become clean and easy to read at a glance.

SHOW NAME OF AUTHOR OF THE POST IN WORDPRESS

<?php the_author() ?>

NAME OF CATEGORY OF THE EXISTING POST WITHIN A WORDPRESS THEME

<?php the_category(', ') ?>

SHOW NUMBER OF COMMENTS IN WORDPRESS THEME

This code will show number of comments in a particular post.
<?php comments_popup_link('No Comments','1 Comment','% Comments'); ?>

SHOWS TAGS IN WORDPRESS THEME UNDER A POST

<?php the_tags('Tags: ',', ','<br />'); ?>

SHOW LIST OF CATEGORIES IN WORDPRESS THEME

This post will show list of categories.Add this code in your page when you don’t want to use widget.
<?php wp_list_categories('show_count=&title_li'); ?>

SHOW LIST OF ARCHIVES IN WORDPRESS THEME

<?php wp_get_archives('type=monthly'); ?>

CODE FOR POPULAR POST IN WORDPRESS THEME

<?php $rand_posts= get_posts('numberposts=4&orderby='); foreach($rand_postsas$post) : ?>    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?phpendforeach; ?>

RECENT POST OF A PARTICULAR CATEGORY IN WORDPRESS THEME

Using this code you can get the recent post of a partivular category.You can show number of post you want to show by editing the value “‘numberposts=5″ .You have to add the category id in “category=1″.
<ul><?phpglobal$post;$myposts= get_posts('numberposts=5&offset=1&category=1');foreach($mypostsas$post) :  setup_postdata($post);?>   <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?phpendforeach; ?></ul>