WP主题制作常用标签代码

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头部主题注释文字

1/*
2Theme Name: 1990c
3Theme URI: http://www.1990c.com
4Author: Lin Yunpeng
5Author URI: http://www.1990c.com
6Description: Lin Yunpeng's theme
7Version: 1.0
8Tags: white,simple
9*/

-----------------------------------------------------------------------------------
header.php常用标签

1<pre>style.css路径<?php bloginfo( 'stylesheet_url' ); ?>
2主题文件夹路径<?php bloginfo('template_directory'); ?>
3主页路径<?php echo get_option('home'); ?>
4wordpress编码<?php bloginfo( 'charset' ); ?>

 

01/*网站标题:
02文章页显示“文章标题 - 博客标题”
03分类页显示“分类标题 - 博客标题”
04其余全显示为“博客标题 - 副标题”*/
05<?php
06if (is_single())
07{the_title();print " - ";bloginfo('name'); }
08else if(is_category())
09{single_cat_title();print " - ";bloginfo('name'); }
10else
11{ bloginfo('name');print " - ";bloginfo('description'); }
12?>

 

01//自定义css的导航调用方法
02<?php
03$args=array(
04'orderby' => 'id',
05'order' => 'ASC'
06);
07$categories=get_categories($args);
08foreach($categories as $category) {
09echo '<li class="thisclass"><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' .$category->name.'</a></li>';
10}
11?>

-----------------------------------------------------------------------------------

sidebar.php常用标签

1//最新文章
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>
4<?php endforeach;?>

 

1// 随机文章
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>
4<?php endforeach;?>

-----------------------------------------------------------------------------------

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(); ?>

 

01//首页文章调用
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(); ?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值