这是wordpress模板高级代码帮助中文版,如果你是个新手,可以看之前的WordPress模板简易代码帮助中文版。
指定example.php中的内容只在首页显示
<?php if ( is_home() ) { include ('example.php'); } ?>
为不同分类指定不同的样式表
<?php if ( is_category('15') ) {
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/cat-15.CSS"
type="text/css" media="screen" />;
<?php } else { ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"
type="text/css" media="screen" />
<?php } ?>
为不同的分类指定不同的图像
<?php if (is_category('7') ):
<img src='<?php bloginfo('template_url');?>/images/cat7.jpg' alt='' />
<?php } elseif (is_category('8') ):
<img src='<?php bloginfo('template_url');?>/images/cat8.jpg' alt='' />
<?php endif; ?>
样式化单篇日志
<div id="post-<?php the_ID();?>">
This snippet will assign the post ID to the DIV. For example, if the ID for the post is 8, that line will echo as
<div id=”post-8”></div>. Now you can style that individual post in the CSS as #post-8. Place this code
within the loop.
上一页和下一页链接
<?php next_posts_link('Next Entries »') ?>
<?php previous_post_link('« Older Entries'); ?>
动态页面链接
<ul>
<li<?php if(is_home()) { ?> class="current_page_item"<?php } ?>><a href="
<?php bloginfo('home'); ?>">home</a></li>
<?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
</ul>
This snippet will rst echo the text “home” with a link to the home page. Next, it will echo the WordPress
pages links in a list, in order dened by your settings, excluding the child pages, and excluding a title
header for the list. If one of the pages in the list is active, the link for that page will be assigned the class
“current_page_item”, which can now be styled in your CSS. Place this code in the template les.
动态页面标题
<?php
if (is_home()) { echo bloginfo('name'); } elseif (is_404()) { echo 'WPCandy » 404'; } elseif(is_search()) { echo 'WPCandy » Search Results'; } else { echo 'WPCandy » '; wp_title(''); }
?>
分类日志
<?php query_posts('cat=2&showposts=5'); ?>
CSS样式表头部声明
/* Theme Name: WPCandy Description: Description goes here Theme URI: http://wpcandy.com/ Version: 2.0 Author: Michael Castilla Author URI: http://wpcandy.com/ Template: Dene a parent template (optional) */
日志循环
The Loop
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
// this is the inside of the loop
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
标签云(Tag cloud)
<?php wp_tag_cloud('smallest=1&largest=9&'); ?>
页面模板头部声明
<?php
/*
Template Name: Gallery
*/
?>
为每个分类指定不同的模板
<?php
$post = $wp_query- >post;if ( in_category('3') ) {
include(TEMPLATEPATH . '/cat3.php’);
} elseif ( in_category('4') ) {
include(TEMPLATEPATH . '/cat4.php');
} else {
include(TEMPLATEPATH . '/cat.php');
} ? >
这是来自WPCandy的电子书翻译而成,你可以通过这里下载。
没有评论:
发表评论