dongzhuang1923 2012-04-22 20:00
浏览 126
已采纳

自定义页面和页面模板wordpress

im using wordpress as a CMS for my personal portfolio website. i want to be able to create different pages that have slightly different variations of the header etc.

after looking around i realised that i can use pages.php and template pages however i do not understand how they work.

for instance currently i made a contact page via creating a new page on the dashboard and doing the html there. i took the permalink and put it inside an 'a' tag that sits in my header. this then goes to that page fine but i want my header to be different.

i guess basically i am confused because the instructions i have looked at do not explain how the page is displayed. in a page template do i do this?

<?php
/*
Template Name: [your page name here]
*/
?>
<?php include(“header_new.php”); ?>

<?php get_footer(); ?>

but what confuses me is how does wordpress know were to put the page?? obviouslly for the index you do a post loop. but all i want is my page to be displayed.

am i missing something like this?...

<?php
/*
Template Name: [your page name here]
*/
?>
<?php include(“header_new.php”); ?>
// POST PAGE FUNCTION HERE>>>>????
<?php get_footer(); ?>

my current theme can be viewed here

hope this is not something obvious that i have missed. many thanks for taking the time to help.

  • 写回答

1条回答 默认 最新

  • duanchun1852 2012-04-22 20:31
    关注

    First take a look at this page template (only an example)

    <?php
    /*
    Template Name: Contact Page
    */
    ?>
    <?php get_header('contact'); ?>
    
        <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(); ?>
    

    If you save above code in a file and name it page-contactpage.php and keep/save it inside your theme's root folder (where index.php is) then it'll be one of your template and you can select this template from template combo box (located at the right side in the page attribute meta box) when you are creating a new page from admin->Add New Page. If you create a page with this template then your page will use this template instead of the default page template.

    Notice the line get_header('contact'); that is a different header I've used instead of the header.php and that header have to be available with name header-contact.php (may be with different content) in the same folder. Now your contact page will use this template with a different header if you select this template when creating it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错