Matt
Matt

Reputation: 395

WordPress formatting issues with front-page.php

Following this tutorial: http://blog.teamtreehouse.com/responsive-wordpress-bootstrap-theme-tutorial

The tutorial instructs me to create an index.php with the contents:

<?php get_header(); ?>

<!-- loop-->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h1><?php the_title(); ?></h1>  
    <?php the_content(); ?>
<?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

<?php get_footer(); ?>

This creates a template with my header on top and footer at the bottom. Then, the tutorial instructs me to create a front-page.php with the contents:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php the_content(); ?>
<?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Basically, the same thing as index.php minus a few lines of code, most importantly the <?php get_header(); ?> and <?php get_footer(); ?> commands. The problem is that, when I create this page, my front page no longer has either its header or its footer, or the formatting that lives within the header and footer.

Yet, on the tutorial, the header, footer, and formatting still apply on the front page. What am I doing wrong?

Upvotes: 0

Views: 85

Answers (3)

Xain Bin Kafeel
Xain Bin Kafeel

Reputation: 29

You can create your custom header and footer as well.

Create your custom header like "header-custom.php"

to include this header you need <?php get_header('custom'); ?> after - is the name of your custom header, when you call the header you need to insert name inside the function like i did above.

for footer also same login & sider bar also same logic.

footer-custom.php, sidebar-custom.php

<?php
get_footer('custom');
?>

<?php 
get_sidebar('custom');
?>

Thanks.

Upvotes: 0

Ahmad Essam
Ahmad Essam

Reputation: 1104

You are doing nothing wrong. The developer probably forgot to mention adding it, that's all.

When you use front-page.php, WordPress doesn't use index.php when rendering the front page and there is no way to include the header and the footer unless you add get_header() and get_footer() to front-page.php.

Add the header and the footer and you should see your front page as the screenshot in the tutorial, and notify the developer to fix this in his tutorial

Upvotes: 1

vinit
vinit

Reputation: 115

hi Matt create a page home template and call header and footer in it then you an call posts its worked.

Upvotes: 0

Related Questions