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();

?>

相关推荐
zzb15808 小时前
RAG from Scratch-优化-query
java·数据库·人工智能·后端·spring·mybatis
必胜刻9 小时前
RESTful 基础:资源、路径与方法对应关系详解
后端·restful
MaximusCoder9 小时前
等保测评命令——Anolis Linux
linux·运维·服务器·网络·经验分享·安全·php
XPoet9 小时前
AI 编程工程化:Hook——AI 每次操作前后的自动检查站
前端·后端·ai编程
J2虾虾9 小时前
在SpringBoot中使用Druid
java·spring boot·后端·druid
Elastic 中国社区官方博客10 小时前
Elastic 为什么捐赠其 OpenTelemetry PHP 发行版
大数据·开发语言·elasticsearch·搜索引擎·信息可视化·全文检索·php
程序员小假10 小时前
为什么要有 time _wait 状态,服务端这个状态过多是什么原因?
java·后端
qwert103711 小时前
跨域问题解释及前后端解决方案(SpringBoot)
spring boot·后端·okhttp
syjy211 小时前
WoodMart电商主题使用教程(含下载)
wordpress·woodmart