自定义首页的模板层次结构
静态页面: WordPress使用 静态页面 模板层次结构: 自定义页面模板 页面-{id}.php page-{slug}.php页面 页面.php 索引.php
您最近的帖子: WordPress使用 博客文章索引 模板层次结构: 家用.php 索引.php
自定义网站首页模板
前页面.php 一个 自定义页面模板 (例如。 模板-功能.php 用于特色内容)
自定义博客帖子索引页模板
家用.php
如果正确配置了静态首页功能,WordPress将不会使用自定义页面模板来显示博客文章索引,即使将自定义页面模板分配给指定为“文章页面”的页面也是如此。 WordPress将 只有 使用其中之一 家用.php 或 索引.php . 当自定义页面模板被分配给指定为“帖子页面”以外的静态页面时,博客帖子索引循环分页将无法正常工作。
上下文条件标记
是前台页面
是家(_H)
front-page.php的配置
front-page.php中的条件显示
if('posts'==get_option('show_on_front')){ 包含(get_home_template()); }其他{ //此处显示自定义内容标记 }
if('posts'==get_option('show_on_front')){ 包含(get_home_template()); }其他{ include(get_page_template()); }
筛选frontpage_template
函数主题lug_filter_front_page_template($template){ 返回is_home()?“”:$ 模板; } add_filter(‘frontpage_template’,‘themeslug_filter_front_page_template');
将自定义查询循环添加到front-page.php
<;? php(电话) if(have_posts()):while(haver_posts)):the_post(); //做点什么 endwhile; 其他: //找不到帖子 endif;
$latest_blog_posts=新WP_Query(数组('posts_per_page'=>;3)); 如果($latest_blog_posts->;have_posts(); post(); //此处显示循环输出 endwhile; endif;