Static page as frontpage, but not from template

2019-06-08 15:43发布

I just want to use a static page as frontpage, but it must be totally different from the posts template.

I can create a static page that can act as front page, but it use the template.

There is a way to create a full static page that don't use the template ???

Thanks !

标签: wordpress
2条回答
走好不送
2楼-- · 2019-06-08 15:56

Create a custom page template and when you are creating your page in WordPress using Pages->Add new then select the template you want to use for the page.

To create a custom page template create a new php file in your theme's root folder and name it page-myCustompage.php (you can use any name but use "page-" as a prefix) and then write code and save it like following (only an example)

<?php
/*
Template Name: Full Width
*/
?>

<?php get_header(); ?>
    <!--Code goes here, below is an example of code that I'm currently using for a custom page template-->
    <div id="post-wrap" class="full-width-wrap">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <h1 class="page-title"><?php the_title(); ?></h1>           
            <?php the_content(); ?>
            <?php endwhile; ?>
            <?php endif; ?> 
    </div>

<?php get_footer(); ?>

To create a custom page template it's better to copy the page.php file's code and paste it inside the new page template and then edit and save it.

For more information see here.

enter image description here

This is a screen shot of my WordPress' "add new page" page and you can see I've two more page templates available and these are because I've those template files inside my theme's root folder.

查看更多
Bombasti
3楼-- · 2019-06-08 16:08

Adding to the other answer, you can make an entire html page and use it inside wordpress as long as you put at the top:

<?php
/*
Template Name: Custom Template Name
*/
?>

Of course, switch "Custom Template Name with the name you choose.

You will need to create this in a text editor like notepad++ or whatever you like and save it as frontpage.php or what name you choose. Then upload to your theme file via FTP.

When making your page, including:

<?php get_header(); ?>

will take care of your DOCTYPE and < head > information, then finish building the page.

You can use other template tags too if you want to pull in your footer or sidebar or whatever.

Make sure to close your body and html tags in the bottom if you don't call the footer template.

When you want to publish it, create a blank page and choose it as your template when you publish.

Then choose it as your static front page in wordpress settings.

查看更多
登录 后发表回答