doubu1964 2015-09-24 08:12
浏览 65
已采纳

WordPress - 创建页面模板

I converted one static website (HTML + PHP) to WordPress following this guide:https://www.elegantthemes.com/blog/tips-tricks/converting-html-sites-to-wordpress-sites

The Site was structured like this:

**Website Folder
     **css folder
     **images folder
     - index.php
     - head.php
     - header.php
     - footer.php
     - page1.php
     - page2.php
     - page3.php

In the head.php file there was the code inside <head> tag of html, in header.php the <header> of the website (logo and nav menu), in the footer.php the <footer> section. I successfully converted the homepage of the site but the guide doens't say how to make the navigation menu dynamic and also create page templates in order to include page1, page and page3 content. Anyone can help me doing this? Thank you

  • 写回答

2条回答 默认 最新

  • doudao1950 2015-09-24 09:14
    关注

    https://developer.wordpress.org/themes/basics/template-hierarchy/

    This article has detailed description of WordPress Template Hierarchy, for example, template name to render a page can in form page-{slug}.php. Also here is an article that explains how to use custom names for page templates, for example custom_page.php, to do that just add opening PHP comment to the file that states the template name.

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

    , and go to the Page > Edit screen to select the custom template for the page.

    Here is also article that explains how to add navigation menu.

    Example ( taken from the link above ):

    // functions.php, register menu
    function register_my_menu() {
      register_nav_menu('header-menu',__( 'Header Menu' ));
    }
    add_action( 'init', 'register_my_menu' );
    
    // display menu on theme
    <?php wp_nav_menu( array( 'theme_location' => 'header-menu' ) ); ?>
    
    // Go to Appearance -> Menus panel to add menu items
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog