高级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.

动态页面标题

<?phpif (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的电子书翻译而成,你可以通过这里下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值