制作WordPress模板所需要调用的PHP代码没哪个只是为了单纯的写博而装WordPress自寻苦吃吧?新浪、搜狐…, 选择多不说,而且方便、易用、知名度高。选择这些免费的博客提供商,没有了域名、空间申请注册的麻烦,没有网站备案等待的焦灼,没有主题选择的乱花渐欲迷人眼,没有推广不利的不安…, 那为什么还有那么多人自寻烦扰,明知山有虎,偏向虎山行,亦然绝决地踏上WordPress的迷途呢?只因这个世界,还有一个名词叫专业。就像笔记本就应该选择ThinkPad, Apple, 车就应该选择路虎,切诺基一样,开博,就应该选择WordPress(怎么有点放毒的感觉 )。
当我们还没有成为玩转WordPress于股掌之间的大鸟的时侯,当我们还处于颤颤微微架起WordPress的时侯,当我们还只是满怀梦想的准专业人士的时侯,我们需要一盏明灯,指引我们前进的方向。好的,菜花不用上酸菜了,因为所谓的明灯已经来了:我们接下来要征服的是WordPress模板。如果说买好空间只是买好了房,那么WordPress模板直接决定房子的装修情况。 一天建不成罗马,一天也学不会制作WordPress模板。在接下来,我所想分享的只是制作WordPress模板所需要调用的PHP代码。下面这些都是很简单同时也是最常用的Wordpress代码和它们相关的作用。 WordPress模板基本文件 style.CSS 样式表文件 WordPress Header头部 PHP代码 注: 也就是位于<head>和</head>之间的PHP代码 <?php bloginfo(‘name’); ?> 网站标题 WordPress 主体模板 PHP代码 <?php the_content(); ?> 日志内容 其它的一些Wordpress模板代码 /%postname%/ 显示博客的自定义永久链接 看到这里的时侯,有人露出不屑的神色。太菜了?看样子,不露出点真功夫还不能服众啊!接着,再来: 指定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: WPChineseoa Description: Description goes here Theme URI: http:// Version: 2.0 Author: TonyDeng Author URI: http:// 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’); } ? >
呵呵,有点晕了吧!要的就是这种感觉, 看来还是英文管用啊! |
|