---
title: "使用 WordPress 搭建企业网站"
author: "CN.Silva..."
date: "2009-04-27T09:50:28Z"
tags: []
slug: "wordpress"
draft: false
lastmod: "2009-04-27T09:50:28Z"
id: 375331
url: "https://i-silva.iteye.com/blog/375331"
---

[WordPress](http://wpchina.org/) 的强大之处，在于其框架的开放性。使用 WordPress 不仅可以用来搭建个人博客，也可以用来建设企业网站。今天这位网友投递的这篇文章，就是介绍如何**使用 WordPress 来搭建企业网站** 的。

在看该文档之前需要对WordPress主题模板的层次架构有一定的了解。简单介绍如图：

![](http://pic.wpchina.org/w-20090413-wp-enterprise-template.png)

更详细的WordPress主题模板的结构层次请见：[wordpress主题结构层次图](http://marslau.com/archives/224.html)

### 一．WordPress搭建中小企业网站思路

WordPress是基于文章的博客程序，而企业或产品网站也是基于一篇篇的文章，所以用WordPress搭建企业网站是可行的。用WordPress建中小企业站模板的思路如下：

#### 1)  大分类+子分类：

首先，根据需求明确网站的整体结构，需要几大类的内容，如分为1产品介绍，2技术中心，3关于我们，4 试用购买，这些内容可以放在网站的主菜单上。

然后，细化网站结构，既明确子分类，如：

![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-1-1.png)

由上图可以清晰的了解网站的结构，上图中 ![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-1-2.png) 表 示该文章分类的id号，因为WordPress本身有一个未分类和链接占用分类的1、2两个id号，我们只能从3开始，图中id为3、4、5、6的几个分 类为大分类；而7、8、9、10为3的子分类，其他父子分类关系也如此。子分类可作为网站内页的side里的内容。值得一提的是， ![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-1-3.png) 表示文章，“关于公司”、“联系我们”、“合作伙伴”三个文章是直接属于大分类5，这个网站的“关于我们”内页side里既有分类又有文章，如何解决？下边会有介绍。现在整体的大思路应该很明确了就是 大分类+子分类。

#### 2)  让每个大分类内页的side里显示子分类：

如图：

![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-2-1.png)

这是我们要的效果 ， 因为我们每个大分类下面都要显示各自的子分类 ， 所以在 sidebar.php 里的分类列表只写 &lt;?php wp\_list\_cats(’child\_of=5′); ?&gt;  已经不能满足我们的需求。因此需要写一个if判断语句：

这个if语句帮我们解决了在每个大分类下面调用其各自子分类。

01. &lt;?php $post = $wp\_query -&gt; post ;
02. if   ( in\_category ( ' 3 ' ) | in\_category ( ' 7 ' ) | in\_category ( ' 8 ' ) | in\_category ( ' 9 ' ) | in\_category ( ' 10 ' ))     &lt;!-- 如果文章属于大分类 3 及其所有子分类 7 、 8 、 9 、 10 时 --&gt;
03. {   wp\_list\_cats ( ' child\_of= 3 ' ) ; }    &lt;!-- 则显示分类 3 的子分类 --&gt;
04. elseif   ( in\_category ( ' 4 ' ) | in\_category ( ' 11 ' ) | in\_category ( ' 12 ' ) | in\_category ( ' 13 ' ) | in\_category ( ' 14 ' ))
05. {   wp\_list\_cats ( ' child\_of= 4 ' ) ; }
06. elseif   ( in\_category ( ' 5 ' ) | in\_category ( ' 15 ' ) | in\_category ( ' 16 ' ))
07. {   wp\_list\_cats ( ' child\_of= 5 ' ) ; }
08. elseif   (   in\_category ( ' 6 ' ))
09. {   wp\_list\_cats ( ' child\_of= 6 ' ) ; }
10. ?&gt;

但上面我们所提到的“关于我们”的side里是“文章+子分类”的列表，所以以上代码也不能完全满足，需要在 { wp\_list\_cats(’child\_of= 5 ‘);} 里加入已发文章的静态链接。如下：

1. {
2. ?&gt;
3. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about/company/" title="关于公司"&gt;关于公司&lt;/a&gt;&lt;/li&gt;
4. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about/contact/" title="联系我们"&gt;联系我们&lt;/a&gt;&lt;/li&gt;
5. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about/partner/" title="合作伙伴"&gt;合作伙伴&lt;/a&gt;&lt;/li&gt;
6. &lt;?php
7. wp\_list\_cats ( ' child\_of = 5 ' ) ;
8. }

现在side里“文章+子分类”的列表，我们很好的解决了。由此启发，当我们在点击各大分类下side列表不一定都用分类，因为如果是分类的话，右 边调用的是 category .php，显示分类页。如果每个大分类下都是这样显示分类列表的话，看起来还是很像blog，不像企业网站。所以我们的网站构架要改一下了，如图： ![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-2-2.png)

正如图中所示有两种方法实现：一是写一篇该子分类概述的文章，文章里有其他该子分类的链接，把概述文章的链接用刚才所述的方法写在 sidebar.php里；另外一种是写一个子分类概述page页面把链接写在sidebar里。这里我们采取第一种方法。因为用page的话会导致页面 过多不好管理，而且page的url地址为： http://域名/页面缩略名/ 的结构，这样就不好识别是哪个分类的内容了。改完的代码如下：

01. &lt;ul&gt;
02. &lt;?php   $post = $wp\_query -&gt; post ;
03. if   ( in\_category ( ' 3 ' ) | in\_category ( ' 7 ' ) | in\_category ( ' 8 ' ) | in\_category ( ' 9 ' ) | in\_category ( ' 10 ' ))
04. {
05. ?&gt;
06. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /products/products- all/production/" title="产品概括"&gt;产品概括&lt;/a&gt;&lt;/li&gt;
07. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /products/features /functions-and-features/" title="功能特点"&gt;功能特点&lt;/a&gt;&lt;/li&gt;
08. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /products/strength /strength/" title="核心优势"&gt;核心优势&lt;/a&gt;&lt;/li&gt;
09. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /products /application/report-appdeployment/" title="部署与运用开发"&gt;部署与运用开发&lt;/a&gt;&lt;/li&gt;
10. &lt;?php
11. }
12. elseif   ( in\_category ( ' 4 ' ) | in\_category ( ' 11 ' ) | in\_category ( ' 12 ' ) | in\_category ( ' 13 ' ) | in\_category ( ' 14 ' ))
13. {   wp\_list\_cats ( ' child\_of=4 ' ) ; }    / * 该分类是“技术中心 " ，需要它为子分类，就直接调用其子分类 \*/
14. elseif ( in\_category('5')|in\_category('15')|in\_category('1 6'))
15. {
16. ?&gt;
17. &lt;li&gt;&lt;a href= " &lt;? php   bloginfo ( ' url ' ) ; ?&gt; /about/company/" title="关于公司"&gt;关于公司&lt;/a&gt;&lt;/li&gt;
18. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about/contact/" title="联系我们"&gt;联系我们&lt;/a&gt;&lt;/li&gt;
19. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about/partner/" title="合作伙伴"&gt;合作伙伴&lt;/a&gt;&lt;/li&gt;
20. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about /news/" title="企业新闻"&gt;企业新闻&lt;/a&gt;&lt;/li&gt;
21. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about /cases/" title="成功案例"&gt;成功案例&lt;/a&gt;&lt;/li&gt;
22. &lt;?php
23. }
24. elseif   ( in\_category ( ' 6 ' ))
25. {
26. ?&gt;
27. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about/download/" title="下载试用"&gt;下载试用&lt;/a&gt;&lt;/li&gt;
28. &lt;li&gt;&lt;a href=" &lt;?php   bloginfo ( ' url ' ) ; ?&gt; /about/purchase/" title="购买产品"&gt;购买产品&lt;/a&gt;&lt;/li&gt;
29. &lt;?php
30. }
31. ?&gt;
32. &lt;/ul&gt;

至此，sidebar里的子分类（文章）列表已经改完。

接着，需要在子分类上标上该大分类的名称，这一点我仍是采用了if语句将其写死。

01. &lt;h3&gt;
02. &lt;?php
03. if   ( in\_category ( ' 3 ' ) | in\_category ( ' 7 ' ) | in\_category ( ' 8 ' ) | in\_category ( ' 9 ' ) | in\_category ( ' 10 ' ) )
04. {
05. ?&gt;
06. 产品介绍
07. &lt;?php
08. }
09. elseif   ( ( in\_category ( ' 4 ' ) | in\_category ( ' 11 ' ) | in\_category ( ' 1 2 ' ) | in\_category ( ' 13 ' ) | in\_category ( ' 14 ' ) )
10. {
11. ?&gt;
12. 技术中心
13. &lt;?php
14. }
15. elseif   (   in\_category ( ' 5 ' ) | in\_category ( ' 15 ' ) | in\_category ( ' 1 6 ' ) )
16. {
17. ?&gt;
18. 关于我们
19. &lt;?php
20. }
21. elseif   ( in\_category ( ' 6 ' )) {
22. ?&gt;
23. 试用购买
24. &lt;?php
25. }
26. ?&gt;
27. &lt;/ h3 &gt;

至此，sidebar里的title名称也写完了。sidebar里的子分类（文章）模块内容也全都完成，如若需要可在下面再写点热点链接之类的内容。

  最后，single.php、category.php、 archive.php (企业网站它的用处不大)、index.php等都可以调用该sidebar.php了。

### 3)  菜单调用大分类

Sidebar做好了，下面就让菜单上显示调用的大分类，调用 &lt;?php wp\_list\_cats(’include=3,4,5,6′); ?&gt; 这句函数即可。include=ID：是我们调用的大类，多个大类的ID号用英文“,”隔开。

#### 4)  修改category.php

现在菜单上列出的是大分类调用，这样每个大分类下面就都会显示分类列表，但如果现在有的大分类不想显示分类列表，而显示该分类的第一篇文章，就需要来修改category.php文件了。思路和修改sidebar差不多。最初 category.php的结构应该如下：

1. &lt;?php get\_header () ; ?&gt;
2. &lt;?php   get\_sidebar () ; ?&gt;
3. &lt;div id="content"&gt;
4. /\*这里是调用分类的内容\*/
5. &lt;/div&gt;
6. &lt;?php   get\_footer () ?&gt;

现在因为需要点击大分类3、5、6时，页面上展示的是文章而非分类列表，所以在 &lt;div id= ” content ” &gt;&lt;/div&gt;里添加一个if语句：

![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-4-1.png)

把以前的 /\*这里是调用分类的内容\*/   ![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-4-2.png) 的 ![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-4-3.png) 中。

而需要在结构中添加的是大分类3、5、6中 ![](http://pic.wpchina.org/w-20090413-wp-enterprise-template-1-4-4.png) 这一块的内容，代码如下

1. &lt;?php query\_posts ( ' name=production ' ) ; ?&gt;
2. &lt;div class="post" &gt;
3. &lt;?php   while ( have\_posts ()) : the\_post () ; ?&gt;
4. &lt;h2&gt;&lt;a href=" &lt;?php   the\_permalink ()    ?&gt; "   class="homesidetext1″ title=" &lt;?php the\_title () ?&gt; "&gt; &lt;?php the\_title () ?&gt; &lt;/a&gt; &lt;/h2&gt;
5. &lt;div class="entry"&gt;
6. &lt;?php   the\_content ( ' Read the rest of this entry » ' ) ;  ?&gt;
7. &lt;/div&gt;
8. &lt;?php   endwhile ; ?&gt;
9. &lt;/div&gt;

query\_posts()是获取文章，其内参数可用 ’ p=文章ID ’ 或 ’ name=文章缩略名 ’ 来调用想放在大分类下首页的文章；

&lt;h2&gt;&lt;/h2&gt;里是文章名称；

the\_content(); 是调用文章内容。

这样就可以在菜单中列出的大分类上点击，出来想要的文章或分类列表了。

以上几点就是企业级网站全站用WordPress搭建的大致思路。

### 二．注意事项

1、  这样的主题模板要基于WordPress的数据库，因为在写side时用到了分类的id号。

2、  正是因为第一条，这样的WordPress主题模板没有通用的，只能因企业而异。

3、  永久链接最好用 /%category%/%postname%/ （分类+文章缩略名）的形式，这样url地址会看起来更有结构性，看起来也更像企业或产品网站。

效果可见：[www.bonzerreport.com](http://www.bonzerreport.com/) ，是不是从中找不到blog的影子了。

原文链接：[WordPress搭建企业网站](http://marslau.com/archives/86.html)