WordPress主题制作(八):制作文章单页模板single.php
2023-02-18 16:29:29 时间
有了前面制作index.php的经验,接下来制作single.php将会非常轻松
添加标题
<h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
添加文章分类
<?php the_category('/');//文章分类,多个分类用"/"分割 ?>
添加文章标签
<?php the_tags('<span>', '/', '</span>'); ?>
添加日期
<?php the_time('Y-m-d H:i:s') ?>
添加评论数
<?php comments_number('0', '1', '%'); ?>
添加文章内容
<?php the_content(); ?>
添加文章分页
<?php wp_link_pages('页码:', '', 'number');//当在页面中使用<!--nextpage-->进行分页时,下方显示页码 ?>
添加评论区
注意:目前我们还没有创建comments.php,所以文章页暂时不去显示评论内容
<?php comments_template(); ?>
到这里我们已经基本完成了,但我们还没有调取文章,所以文章页现在仍然没有内容。
在文章标题前加上一句
<?php if(have_posts()) : the_post(); ?>
然后在结尾我们还需要加上当没有文章时,将没有文章的信息告知用户
<?php else : ?>
<?php _e('没有文章...'); ?>
<?php endif; ?>
好了,现在我们可以看到文章内容了,single.php此时也就完成啦。
WordPress主题: 9 / 14
- WordPress主题制作:开始前的准备
- WordPress主题制作(一):主题文件结构
- WordPress主题制作(二):模板和模板文件
- WordPress主题制作(三):牛刀小试
- WordPress主题制作(四):制作头部模板header.php
- WordPress主题制作(五):制作底部模板footer.php
- WordPress主题制作(六):制作侧边栏模板sidebar.php
- WordPress主题制作(七):制作基础模板Index.php
- WordPress主题制作(八):制作文章单页模板single.php
- 计划: WordPress主题制作(九):制作评论区模板comments.php
- 计划: WordPress主题制作(十):制作单页(非文章)模板page.php
- 计划: WordPress主题制作(十一):制作静态首页front-page.php
- 计划: WordPress主题制作(十二):创建您自己的小工具
- 计划: WordPress主题制作(十三):创建后台主题选项
本文采用 「CC BY-NC-SA 4.0」创作共享协议,转载请标注以下信息: 原文出处:Yiiven https://www.yiiven.cn/wordpress-theme-single.html
相关文章
- 【华为云技术分享】MongoDB经典故障系列五:sharding集群执行sh.stopBalancer()命令被卡住怎么办?
- GitHub车牌检测识别项目调研
- Linux基础-学会使用命令帮助
- Linux 基础-新手必备命令
- Linux 基础-文件及目录管理
- Linux 基础-文本处理命令
- Linux 基础-文件权限与属性
- Linux 基础-查看进程命令 ps 和 top
- Linux基础-查看和设置环境变量
- Linux 基础-查看 cpu、内存和环境等信息
- MongoDB从入门到实战之.NET Core使用MongoDB开发ToDoList系统(2)-Swagger框架集成
- MongoDB从入门到实战之.NET Core使用MongoDB开发ToDoList系统(1)-后端项目框架搭建
- MongoDB从入门到实战之MongoDB工作常用操作命令
- MongoDB从入门到实战之Docker快速安装MongoDB
- MongoDB从入门到实战之MongoDB快速入门
- MongoDB从入门到实战之MongoDB简介
- MongoDB安全加固,防止数据库攻击删除勒索威胁
- Docker安装MongoDB并使用Navicat连接
- OCI runtime exec failed: exec failed: unable to start container process: exec: "mongo": executable file not found in $PATH: unknown
- Visual Studio 2022 git error Unable to negotiate with xx.xxx.xxxx port 22: no matching host key type found. Their offer: ssh-rsa