通过前面我们来添加网站的标题和副标题,把文章标题显示出来,添加类别,作者和日期,首页的内容展示 把一个首页该展示的大部分内容都显示出来。
今天,我们来添加网页的侧边栏,目前使用固定的方式把侧边栏展示出来。
打开wp-content/themes/test/index.php文件。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?php bloginfo('name');?></title>
</head>
<body>
<h1><a href ="<?php bloginfo('url');?>"><?php bloginfo('name');?></a></h1>
<?php bloginfo('description');?><br/>
<div>
<?php if(have_posts()):?>
<?php while(have_posts()):?>
<?php the_post();?>
<h2><a href="<?php the_permalink();?>" title="<?php the_title();?>"><?php the_title();?></a></h2>
<div>
<?php _e('类别:');?><?php the_category(' ')?>
<br/>
<?php _e('作者:');?><?php the_author();?>
<?php _e('发表日期:');?><?php the_time(get_option('date_format'));?>
<?php comments_popup_link('无评论»','有1条评论»','有%条评论»');?>
<?php edit_post_link('编辑','<p>','</p>');?>
</div>
<div>
<?php the_excerpt();?>
</div>
<?php endwhile;?>
<div class ="navigation">
<?php posts_nav_link(' ','上一页','下一页');?>
</div>
<?php endif;?>
</div>
<div>
<ul>
<li><h2>分类目录</h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0');?>
</ul>
</li>
<li><h2>文章归档</h2>
<ul>
<?php wp_get_archives('type = monthly');?>
</ul>
</li>
<li><h2>最新文章</h2>
<ul>
<?php get_archives('postbypost', 10);?>
</ul>
</li>
</ul>
</div>
</body>
</html>
展示的侧边栏内容如图:

这里用一个div承载所有侧边栏,用无序列表标签ul来展示需要的内容。
<?php wp_list_cats(‘sort_column=name&optioncount=1&hierarchical=0’);?>
wp_list_cats() 函数,多数情况下用 sort_column=name&optioncount=1&hierarchical=0 这个参数就可以展示出所有分类,以及分类含有的文章数量。
具体的参数使用说明,由于内容很多,这里不过多详述。有兴趣的朋友可以把 sort_column,sort_order,list,optiondates,optioncount,hide_empty,use_desc_for_title,children,hierarchical,child_of,exclude,feed,feed_image 这些参数测试下,当然我闲的无聊真全都试过。
<?php wp_get_archives(‘type = monthly’);?>
wp_get_archives() 函数由于他的参数同wp_list_cats一样,很多,而且参数的取值返回更多,这里就把参数理下。
array( 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC', 'post_type' => 'post' );
由于参数里的type值可以取如下内容:
- yearly:按年份归档
- monthly:按月份归档
- daily:按天归档
- weekly:按周归档
- postbypost:按发表日期列出所有文章
- alpha:按文章标题排序列出所有文章
看到这里我们先不说下面其他项的取值。大家是不是认识到这个函数功能很强大。这里不一一举例,大家可以动手尝试下,对于这个函数的理解会更加深刻。
<?php get_archives(‘postbypost’, 10);?>
get_archives() 这个函数,看上去是不是和前面一个函数长的有点像,就是少了个前缀wp_。是这样的,这两个函数的参数只是使用的方式不一样,但是结果是一样的。
比如: get_archives(‘monthly’) 和 wp_get_archives(‘type = monthly’) 是同样按月来归档文章。
再比如: get_archives(‘postbypost’, 3) 和 wp_get_archives(‘type=postbypost&limit=3’) 也是一样的输出最新的3篇文章。
所以,如果测试过wp_get_archives()函数的各个参数,对于get_archives()函数而言,只是变了一种形式而已。
从零开始建造自己的wordpress主题:
为什么要自己做 WordPress 主题
WordPress主题的基本结构
从index.php开始
我们来添加标题和副标题
把文章标题显示出来
添加类别,作者和日期
首页的内容展示
添加侧边栏
“添加侧边栏”上的25条回复
cialis on paypal viagra/cialis cialis voucher
what color is viagra women and viagra viagra walmart
how long does it take for a cialis to kick in cialis one a day price cialis generico india
everett cash advance debit card payday loans california loan money agreement letter
domestic cialis online cheap cialis 5mg no prescription buy cialis online