• WordPress主题开发:主题初始化


    在最简单的情况下,一个WordPress主题由两个文件构成:

    index.php ------------------主模版

    style.css  -------------------主样式表(注意的是两个不同的主题是不允许拥有相同的表述 , 这样会导致主题选择出错的。

    简版:

    /*
    Theme Name:企业主题练习
    Author:tinyphp
    Author URI: http://www.cnblogs.com/tinyphp/
    Description: 经典企业主题
    Tags: 蓝色 商务
    */

    完善版:

    /*
    Theme Name: 主题名称
    Theme URI: 主题介绍地址(如果你的主题上传到wordpress官方资源处适用)
    Author: 主题的作者
    Author URI: 主题作者的网址
    Description: 主题的描述
    Version: 主题的版本
    License: GNU General Public License v2 or later【版权说明】
    License URI: http://www.gnu.org/licenses/gpl-2.0.html 【版权说明的网址】
    Tags: 主题的标签,如果你的主题上传到官方指定处,通过此标签可以被筛选出
    Text Domain: twentythirteen【如果主题提供多国语言版本,适用】
    
    This theme, like WordPress, is licensed under the GPL.
    Use it to make something cool, have fun, and share what you've learned with others.
    */

    用于声明主题名称、主题url、主题版本、主题描述、作者、作者网址

    主题安装:

    主题预览图:命名为 screenshot.png ,放在你的主题的根目录下。

    主题的安装:在后台外观->添加主题,把.zip格式的主题上传即可在后台编辑。

    WordPress主题安装后,目录位于 wp-content/themes/

    或手动在wp-content/themes/下创建文件夹

    引用样式:

    引用style.css

     <link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />

    引用某个样式方法1

    <link rel="stylesheet" href="<?php bloginfo('template_url');?>css/mystyle.css" type="text/css" media="screen" />

    引用某个样式方法2

    <?php
    wp_enqueue_style( 'init_style',get_bloginfo('template_url').'/css/mystyle.css');
    ?>

    目录说明:

    404.php 404页面模板
     rtl.css  如果网站的阅读方向是自右向左的,会被自动包含进来
    comments.php  评论模板
    single.php 文章模板。显示单独的一篇文章时被调用,如果模板不存在会使用 index.php
    single-<post-type>.php 自定义单独页面模板如: single-books.php 展示自定义文章类型为 books的文章,如果模板不存在会使用 index.php
    page.php 页面模板
    category.php 分类目录模板
    tag.php 标签模板
    taxonomy.php 术语模板。请求自定义分类法的术语时使用
    author.php 显示作者资料模板
    date.php 显示按日期/时间归档的模板
    archive.php 显示某条件下的归档,如果category.php存在则使用category.php
    search.php 搜索结果模板
    attachment.php 查看单个附件时使用的模板
    image.php 图片附件模板,查看单个图片时将调用此模板,如果不存在此模板,则调用attachment.php 模板
    sidebar.php 侧边栏模板
    header.php  页眉模板
    footer.php 页脚模板
    functions.php 扩展功能配置文件

     基本首页:index.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
           <?php wp_head(); ?>
    </head>
    <body>
        <?php wp_footer(); ?>
    </body>
    </html>

    升级头部(header.php)

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
        <head>
            <meta charset="<?php bloginfo( 'charset' ); ?>" />
            <title><?php wp_title(); ?></title>
            <meta name="description" content="<?php bloginfo( 'description' ); ?>">
            <link rel="profile" href="http://gmpg.org/xfn/11" />
            <link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />
            <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
            <?php if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); ?>
            <?php wp_head(); ?>
        </head>

     <html> 开始标签应该包含 language_attributes()

    使用 bloginfo() 设置 <meta> 字符集和description元素

    使用 wp_title() 设置 <title> 元素

    使用 get_stylesheet_uri() 来获取当前主题的样式表文件

    使用 Automatic Feed Links 添加 feed 链接

    需添加声明 wp_head() 到 </head> 结束标签的前面

  • 相关阅读:
    Nginx会话保持之nginx-sticky-module模块
    企业级分布式应用服务EDAS _Dubbo商业版_微服务PaaS平台 【EDAS Serverless 运维 创业】
    git repository description
    运维成长
    jenkins+maven+tomcat集群发布
    Leaf——美团点评分布式ID生成系统 UUID & 类snowflake
    tomcat redis 集群 session共享
    JEECG & JEESite Tomcat集群 Session共享
    分布式Tomcat session会话Sticky Sessions问题
    Memcached 集群架构与memcached-session-manager
  • 原文地址:https://www.cnblogs.com/tinyphp/p/4391182.html
Copyright © 2020-2023  润新知