wordpress 2014主题 页面讲解 一
2014-11-19 12:33
239 查看
index.php
<?php /** * The main template file * * This is the most generic template file in a WordPress theme and one * of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query, * e.g., it puts together the home page when no home.php file exists. * * @link http://codex.wordpress.org/Template_Hierarchy * * @package WordPress * @subpackage Twenty_Fourteen * @since Twenty Fourteen 1.0 */ get_header(); ?> <div id="main-content" class="main-content"> <?php if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
整段代码的意思是 如果是首页并post的tag为featured,那么调用featured_content.php模板
twentyfourteen_has_featured_posts函数在functions.php中,源码为
/**
* A helper conditional function that returns a boolean value.
*
* @since Twenty Fourteen 1.0
*
* @return bool Whether there are featured posts.
*/
function twentyfourteen_has_featured_posts() {
return ! is_paged() && (bool) twentyfourteen_get_featured_posts();
}
返回一个布尔值
是否分页
执行twentyfourteen_get_featured_posts()函数,这个函数返回一个数组,如果是空的则是false
/**
* Getter function for Featured Content Plugin.
*
* @since Twenty Fourteen 1.0
*
* @return array An array of WP_Post objects.
*/
function twentyfourteen_get_featured_posts() {
/**
* Filter the featured posts to return in Twenty Fourteen.
*
* @since Twenty Fourteen 1.0
*
* @param array|bool $posts Array of featured posts, otherwise false.
*/
return apply_filters( 'twentyfourteen_get_featured_posts', array() );
}
注册一个名为twentyfourteen_get_featured_posts的过滤器,返回一个空数组。
// Include the featured content template get_template_part( 'featured-content' );
调用模板 featured_content.php用法为
<?php get_template_part( $slug, $name ) ?>
第一个参数是别名
} ?>
<div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php if ( have_posts() ) : // Start the Loop. while ( have_posts() ) : the_post(); /* * Include the post format-specific template for the content. If you want to * use this in a child theme, then include a file called called content-___.php * (where ___ is the post format) and that will be used instead. */ get_template_part( 'content', get_post_format() );
/*
* get_template_part 主要是获取子模板
* get_post_format()主要是获取当前文章属于哪种,然后加载相应的模板
* 所以他的模板文件就是content-aside.php,content-chat.php等。
* 如果以上某一个不存在,就会自动调用content.php
*/
endwhile; // Previous/next post navigation. twentyfourteen_paging_nav(); else : // If no content, include the "No posts found" template. get_template_part( 'content', 'none' ); endif; ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar( 'content' ); ?> </div><!-- #main-content --> <?php get_sidebar(); get_footer();
相关文章推荐
- wordpress 2014主题 页面讲解 二
- WordPress主题开发: 制作文章页面single.php
- 关于WordPress.LightWord主题的404页面
- wordpress主题开发教程手记:模板文件的结构讲解
- wordpress:页面-默认外观主题页面模板
- wordpress主题开发教程手记:wp-login.php登录页面优化
- WordPress主题制作教程4:调用指定页面内容
- wordpress主题开发教程手记:启用主题后自动创建页面
- 解决WordPress在新建页面无法选择主题页面模板 WordPress无法识别安装的主题
- WordPress主题开发: 制作文章页面single.php
- WordPress主题制作(6)-关于页面模板
- 以WordPress为例讲解jQuery美化页面Title的方法
- wordpress主题开发常用缓存API的讲解与调用方案
- WordPress主题开发:输出指定页面导航
- 10个完美的WordPress空白主题
- 转化率最高的16个WordPress 电子商务主题
- 用wordpress做企业主题网站
- WordPress 主题教程 #4b:Header 模板 2
- wordpress中防止编辑身份修改页面内容
- 32款精美的WordPress 3.0免费主题