WordPress模板结构
style.css : CSS文件
index.php : 主页模板
archive.php : Archive/Category模板
404.php : Not Found 错误页模板
comments.php : 留言/回复模板
footer.php : Footer模板
header.php : Header模板
sidebar.php : 侧栏模板
page.php : 内容页(Page)模板
single.php : 内容页(Post)模板
searchform.php : 搜索表单模板
search.php : 搜索结果模板
-----------------------------------------------------------------------------------
基本条件判断
is_home() : 是否为主页
is_single() : 是否为内容页(Post)
is_page() : 是否为内容页(Page)
is_category() : 是否为Category/Archive页
is_tag() : 是否为Tag存档页
is_date() : 是否为指定日期存档页
is_year() : 是否为指定年份存档页
is_month() : 是否为指定月份存档页
is_day() : 是否为指定日存档页
is_time() : 是否为指定时间存档页
is_archive() : 是否为存档页
is_search() : 是否为搜索结果页
is_404() : 是否为 “HTTP 404: Not Found” 错误页
is_paged() : 主页/Category/Archive页是否以多页显示
-----------------------------------------------------------------------------------
style.css头部主题注释文字
3 |
Theme URI: http://www.1990c.com |
5 |
Author URI: http://www.1990c.com |
6 |
Description: Lin Yunpeng's theme |
-----------------------------------------------------------------------------------
header.php常用标签
1 |
<pre>style.css路径<?php bloginfo( 'stylesheet_url' ); ?>
|
2 |
主题文件夹路径<?php bloginfo( 'template_directory' ); ?>
|
3 |
主页路径<?php echo get_option( 'home' ); ?>
|
4 |
wordpress编码<?php bloginfo( 'charset' ); ?>
|
07 |
{the_title(); print " - " ;bloginfo( 'name' ); }
|
08 |
else if (is_category())
|
09 |
{single_cat_title(); print " - " ;bloginfo( 'name' ); }
|
11 |
{ bloginfo( 'name' ); print " - " ;bloginfo( 'description' ); }
|
07 |
$categories =get_categories( $args );
|
08 |
foreach ( $categories as $category ) {
|
09 |
echo '<li class="thisclass"><a href="' . get_category_link( $category ->term_id ) . '" title="' . sprintf( __( "View all posts in %s " ), $category->name ) . '" ' . '>' . $category ->name. '</a></li>' ;
|
-----------------------------------------------------------------------------------
sidebar.php常用标签
2 |
<?php $rand_posts = get_posts( 'numberposts=9&orderby=date' ); foreach ( $rand_posts as $post ) : ?>
|
3 |
<li><a href= "<?php the_permalink(); ?>" ><?php the_title(); ?></a></li>
|
2 |
<?php $rand_posts = get_posts( 'numberposts=9&orderby=rand' ); foreach ( $rand_posts as $post ) : ?>
|
3 |
<li><a href= "<?php the_permalink(); ?>" ><?php the_title(); ?></a></li>
|
-----------------------------------------------------------------------------------
index.php常用标签
1 |
调用head.php<?php get_header();?> |
2 |
调用footer.php<?php get_footer();?> |
3 |
调用sidebar.php<?php get_sidebar();?> |
4 |
调用其它文件<?php include (TEMPLATEPATH . '/文件名' ); ?>
|
5 |
显示注册链接<?php wp_register(); ?> |
6 |
显示登录/注销链接<?php wp_loginout(); ?> |
02 |
<?php if (have_posts()) : ?> /*检查是否存在Post/Page*/
|
03 |
<?php while (have_posts()) : the_post(); ?> /*如果存在Post/Page则予以显示 */
|
04 |
<?php the_title(); ?> /*文章标题*/
|
05 |
<?php the_time( 'Y.m.d h:i' ) ?> /*发表时间*/
|
06 |
<?php the_category( ' ' ); ?> /*文章分类*/
|
07 |
<?php comments_popup_link( '0' , '1' , '%' , ”, 'CLOSE' ); ?> /*评论数*/
|
08 |
<?php edit_post_link( 'EDIT' ); ?> /*显示编辑链接*/
|
09 |
<?php the_content( '' ); ?> /*正文内容*/
|
10 |
<?php endwhile ; ?> /*While结束*/
|
11 |
<?php endif ; ?> /*If结束*/
|
-----------------------------------------------------------------------------------
single.php常用标签
1 |
上一篇<?php previous_post_link( '%link' ); ?>
|
2 |
下一篇<?php next_post_link( '%link' ); ?>
|
3 |
评论调用<?php comments_template(); ?> |
4 |
日历调用<?php get_calendar(); ?> |