Header头部 PHP代码
注: 也就是位于<head>和</head>之间的PHP代码
bloginfo(’name’); //网站标题
wp_title(); //日志或页面标题
bloginfo(’stylesheet_url’); //WordPress主题样式表文件style.css的相对地址
bloginfo(’pingback_url’); // WordPress博客的Pingback地址
bloginfo(’template_url’); // WordPress主题文件的相对地址
bloginfo(’version’); // 博客的WordPress版本
bloginfo(’atom_url’); // WordPress博客的Atom地址
bloginfo(’rss2_url’); // WordPress博客的RSS2地址
bloginfo(’url’); // WordPress博客的绝对地址
bloginfo(’name’); // WordPress博客的名称
bloginfo(’html_type’); // 网站的HTML版本
bloginfo(’charset’); // 网站的字符编码格式
主体模板 PHP代码
the_content(); // 日志内容
if(have_posts()) : // 确认是否有日志
while(have_posts()) : the_post(); // 如果有,则显示全部日志
endwhile; // 结束PHP函数”while”
endif; // 结束PHP函数”if”
get_header(); // header.php文件的内容
get_sidebar(); // sidebar.php文件的内容
get_footer(); // footer.php文件的内容
the_time(’m-d-y’) // 显示格式为”02-19-08″的日期
comments_popup_link(); // 显示一篇日志的留言链接
the_title(); // 显示一篇日志或页面的标题
the_permalink(); // 显示一篇日志或页面的永久链接/URL地址
the_category(); // 显示一篇日志或页面的所属分类
the_author(); // 显示一篇日志或页面的作者
the_ID(); // 显示一篇日志或页面的ID
edit_post_link(); // 显示一篇日志或页面的编辑链接
get_links_list(); // 显示Blogroll中的链接
comments_template(); // comments.php文件的内容
wp_list_pages(); // 显示一份博客的页面列表
wp_list_cats(); // 显示一份博客的分类列表
next_post_link('%link') ?//下一篇日志的URL地址
previous_post_link('%link') // 上一篇日志的URL地址
get_calendar(); // 调用日历
wp_get_archives() // 显示一份博客的日期存档列表
posts_nav_link(); // 显示较新日志链接(上一页)和较旧日志链接(下一页)
bloginfo(’description’); // 显示博客的描述信息
其它的一些WordPress模板代码
/%postname%/ 显示博客的自定义永久链接
<?php the_search_query(); ?> 搜索表单的值
<?php _e(’Message’); ?> 打印输出信息
<?php wp_register(); ?> 显示注册链接
<?php wp_loginout(); ?> 显示登入/登出链接
<!–next page–> 在日志或页面中插入分页
<!–more–> 截断日志
<?php wp_meta(); ?> 显示管理员的相关控制信息
<?php timer_stop(1); ?> 显示载入页面的时间
<?php echo get_num_queries(); ?> 显示载入页面查询
页面判断函数
is_home() //主页
is_single() //文章页
is_single((ID) ) //具体文章页
is_page()//页面
is_category()//分类页
is_search()//搜索页
is_404() //404
is_tag() //标签页
获取文件
plugins_url:从插件目录读取
get_theme_file_uri:从当前主题目录文件读取
get_template_directory():读取主题的绝对路径
get_template_directory_uri():读取主题的url路径
get_bloginfo('template_directory').'/文件'; 输出主题根目录的文件
includes_url:从wp-includes路径下读取
wp_enqueue_script()函数:
wp_enqueue_scripts:加载js(在头部 wp_head())前台处理
admin_enqueue_scripts:在后台加载
login_enqueue_scripts:在登录页面加载
wp_print_scripts:只在需要用到的地方加载
wp_register_script:注册
wp_deregister_script:移除注册
wp_enqueue_style()函数:
wp_enqueue_style:前台加载css
wp_deregister_style:取消注册css
判断
is_user_logged_in();
https://wenku.baidu.com/view/ee47d7485bfafab069dc5022aaea998fcc22402e.html
https://blog.csdn.net/weixin_44434230/article/details/112244038