Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need php code to create a static front page for my blog.how do it by php in wordpress.anybody can help me.

share|improve this question
3  
By the way, did you try to search the site for this question before posting? –  Chip Bennett Mar 19 '12 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 Mar 28 '12 at 16:25
add comment

6 Answers

up vote 3 down vote accepted

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:

<?php
/*
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

share|improve this answer
    
thank you so much. –  SANS780730 Mar 20 '12 at 7:18
add comment

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

<?php
/*
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

http://codesmeister.blogspot.in/2011/10/how-to-make-homepage-front-page-in.html

share|improve this answer
add comment

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>

  </div>
<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>

  </li>
<?php endwhile; ?>
</ul>
</div>
<!-- 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;  ?>


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


<?php get_footer(); ?>
share|improve this answer
1  
home.php is not necessary the front page. The name is misleading. Use front-page.php instead. –  toscho Mar 21 '12 at 0:02
add comment

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.

share|improve this answer
    
ok.thanks a lot so much –  SANS780730 Mar 19 '12 at 17:03
add comment

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

share|improve this answer
    
i am asking how to post the data to home page programmatically.. –  SANS780730 Mar 19 '12 at 14:20
add comment

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

share|improve this answer
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 Mar 19 '12 at 13:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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