WordPress 主题初体验:从 style.css 到 index.php、single.php 简单实战

  • 主题创建,再themes目录下创建一个文件夹,例如:cs
  • .创建style.css和index.php文件,后台就多一个主题,启用
  • .定义style.css
    1.Theme Name:主题名称
    2.Theme URI:主题地址
    3.Author:作者
    4.Author URI:作者地址
    5.Description:描述
  1. Version:版本号
    7.License:开源协议
    8.License URI:开源协议地址
    9.Tags:标签
    10.Text Domain:主题目录

三.创建header.php和footer.php,注意看头部和底部的body和html标签组合起来是闭合的

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>测试</title>

</head>

<body>

<?php echo '我是头部';?>

<?php

echo '我是底部';

?>

</body>

</html>

四.index.php加载头部和底部

<?php

get_header();

echo '我是首页';

get_footer();

?>

五.创建archive.php,下面是一个简单的archive.php的代码

<?php

get_header();

if ( have_posts() ) : while ( have_posts() ) : the_post();

echo "<br/>";

echo "我是标题:";

echo "<br/>";

the_title();

echo "<br/>";

echo "我是时间:";

echo "<br/>";

the_date();

echo "<br/>";

echo '我是内容:';

echo "<br/>";

the_content();

echo "<br/>";

endwhile;

endif;

get_footer();

?>

六.创建single.php,可以看到single.php是没有循环的单个文章

<?php

get_header();

echo "<br/>";

echo "我是标题:";

echo "<br/>";

the_title();

echo "<br/>";

echo "我是时间:";

echo "<br/>";

the_date();

echo "<br/>";

echo '我是内容:';

echo "<br/>";

the_content();

echo "<br/>";

get_footer();

?>

相关推荐
根目录下的猫1 小时前
RK3588适配的轻量级AI模型推荐
人工智能·后端·python·目标检测
星栈2 小时前
用 Rust 写 Agent 服务 -- adk-rust 上手记
后端·agent
杨运交3 小时前
[071][验证码模块]基于Spring拦截器的验证码认证设计思想
java·后端·spring
LucianaiB3 小时前
我用豆包工作 Seed-2.1-pro,复刻了 QQ 时代爆红的魔术图片
后端
码事漫谈3 小时前
智谱 ZCode 静默上传 Git 历史:48 小时信任危机复盘
后端
掘金码甲哥4 小时前
当对话模型遇上向量模型,vllm production stack 又该如何应对?
后端
传奇开心果编程4 小时前
【springboot基础语法学与练】第 1 课:从零开始
java·spring boot·后端·学习
IT_陈寒4 小时前
Java线程池用错参数,我的服务居然悄悄崩溃了
前端·人工智能·后端
光影少年4 小时前
Express 中间件原理
后端·node.js·express
aramae5 小时前
MySQL内置函数(7)
开发语言·笔记·后端·mysql·其他