I need the php code to create a static front page for my blog. How do I do it with php in WordPress?

  • 4
    By the way, did you try to search the site for this question before posting? Commented Mar 19, 2012 at 16:14
  • 2
    @SANS780730 - When entering a new question, it automatically searches for you based on your question title. There's a number of relevant results when I tried the same title (they're a little lower down, but still there). I suggest next time you search first and ask questions later. Also, member for 14 days, 19 questions asked, 0 answers given, 2 accepted answers, and 2/3rds of your rep is negative - you may want to rethink your approach here.
    – SickHippie
    Commented Mar 28, 2012 at 16:25

6 Answers 6


From @Ray Mitchel's answer the tutorial shows you how to set a specific page in your blog to be the front page.

Assuming you're using the TwentyEleven theme, you need to learn about page templates. The WordPress site has an article: http://codex.wordpress.org/Pages#Page_Templates.

So you can create a page template by starting by copying the home.php file and renaming it to my-page.php and put the following at the top of the page:

Template Name: Snarfer

Once you have saved the file, in any page you can switch the page template, and in the drop down you should now be able to select 'Snarfer'.

Page Attributes section

Now the correct name for the front page is front-page.php. If you call your file that, the page that you have set to be the front page will automatically use the front-page.php file without you having to set the page template.

Even further to this once you've named your file front-page.php you don't have to bother setting a specific page to be the front page as the front-page.php file will get called instead of home.php (the standard home page). Below you can see why, which is thanks to the WordPress Template Hierarchy the front-page.php file comes above the home.php file if you leave it to display posts on the front page (which is the default):

Template Hierarchy


You don't have to make any template or other programmatic changes just to use a static Page as your site front page:

  1. Create a static Page, give it any arbitrary name (e.g. "Front Page", but it can be anything), and add whatever content to it that you need/want
  2. If you need to display a blog posts index, create a second static Page, again give it any arbitrary name (e.g. "Blog", but it can be *anything). No need to add any content to this page.
  3. Go to Dashboard -> Settings -> Reading
  4. Change "Front page displays" from "your latest posts" to "a static page"
  5. Using the "Front Page" select dropdown, select the static Page you created in Step 1
  6. If you need to display a blog posts index, using the "Posts page" select dropdown, select the static page you created in Step 2

That's all you need to do. Your site now displays a static Page as the front page.


In your theme directory you can add or modify your front-page.php file et code in whatever you want.

  • 1
    i do not known about wordpress.i known only little bit.so tell me how do it? can u give me example code or tutorial link.
    – SANS780730
    Commented Mar 19, 2012 at 13:39

Is this for a theme you are developing, or are you using an existing theme? Quoting from the WordPress codex "Creating a virtual static front page does not require editing or coding of files or templates." In most cases, you can have a static front page by changing the settings in the administration area. Here is the link to that section http://codex.wordpress.org/Creating_a_Static_Front_Page

  • i am asking how to post the data to home page programmatically..
    – SANS780730
    Commented Mar 19, 2012 at 14:20

There are a few right answers to your question. It just depends on how custom you want that home page. What I do is create a home.php file and start with what is contained in my page.php in my theme. Then, I customize it the way I want. If the theme has a home.php file, it uses it for your home page.

For most of my sites I like to start with a slider of some kind, then have maybe three "action" boxes with a photo, headline, link and some text. I accomplish this with a custom post type. Some times I may want to list some of my posts in a small box, sometimes I would like a sidebar, others not.

The point is that I can customize my home page just by customizing this home.php. I will give you one of my standard home.php files below and you can dissect it to see how I use it.

<?php get_header(); ?>
<!--start of home.php -->

  <div id="feature" class="clearfix">

      <div id="feature-center" class="clearfix">
<!-- The shortcode for the slider I am using -->
           <?php echo do_shortcode('[royalslider id="2"]'); ?>

<div id="page-wrap"><!-- FEATURE SLIDER AREA -->
<div id="full-content-top"></div>
<!-- end of content-top -->
<div id="full-content-center" class="clearfix">
<!-- MAIN FOCUS BOXES  -->                
<div id="main-focus-boxes" class="clearfix">
<ul id="post-columns" class="group">
<?php $recent = new WP_Query("post_type=homebox&showposts=3");  while($recent->have_posts()) : $recent->the_post();?>
<li class="one-third clearfix">             
  <div class="boxtitle"><h3><?php the_title(''); ?></h3></div>
  <div class="boximage"><a href="<?php echo get_post_meta($post->ID, 'ecpt_link', $single=true) ?>" ><img align="middle" src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo get_post_meta($post->ID, 'ecpt_boxphoto', $single = true); ?>&w=230&h=150" alt="<?php echo get_post_meta($post->ID, 'ecpt_titleofbox', $single=true) ?>" /></a></div>
  <div class="boxtext"><p><?php echo get_post_meta($post->ID, 'ecpt_boxtext', $single=true) ?></p></div>
  <div class="boxlink"><a class="more-link" href="<?php echo get_post_meta($post->ID, 'ecpt_link', $single=true) ?>" ><?php echo get_post_meta($post->ID, 'ecpt_linklabel', $single=true); ?></a></div>

<?php endwhile; ?>
<!-- end of Main focus boxes -->  
    <!-- Start of the home page welcome content -->   
<?php $recent = new WP_Query("post_type=welcome"); while($recent->have_posts()) : $recent->the_post();?>
  <h1><?php the_title(); ?></h1>
      <?php the_content(''); ?>
 <!-- end of post excerpt -->   
  <?php endwhile;  ?>

<!-- end of content-center -->
<div id="full-content-bottom"></div>
<!-- end of content-bottom --><!-- end of page-content -->

<?php get_footer(); ?>
  • 1
    home.php is not necessary the front page. The name is misleading. Use front-page.php instead.
    – fuxia
    Commented Mar 21, 2012 at 0:02

For that you have to create one PHP file is known as page template in wordpress. page template always start with :

Template Name:Your Home Page Template Name

After that you have to write all other code in page template.

after creating page template file, create one page and switch on page attributes box in this box one drop down list with the name template and select your page template after that publish your page.

for create a static front page read this


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.