64x64 icon dark hosting
Deploy New Relic now and get $135 off your Tuts+ subscription.
Advertisement

WordPress as a Knowledge Base

by

At work we previously used KBPublisher to manage our knowledge base. It costed money, it was hard to style, code is encrypted with ion cube and so on, basically very hard to maintain. WordPress can do the same things and even better.

This tutorial will show you how to use custom taxonomies for knowledge base sections and custom posts for knowledge base articles.


Step 1 Administration

Knowledge base sections and articles need to be managed. WordPress makes this easy to do with custom taxonomies and custom post types.

Just register the new taxonomy and post type. Add the following into functions.php from your theme.

For more information on the ins and outs of this functionality, read our other custom post type and custom taxonomy articles.

This will run after WordPress has finished loading but before any headers are sent, registering the post type and taxonomy. Also, it will add the rewrite rules for the permalinks of the taxonomy and post type.

The register_post_type registers the custom post type, this is used for the KB articles. The register_taxonomy registers the custom taxonomy, this is used for the KB sections. The articles won't be hierarchical but the sections will be, so it gives the possibility to create a tree structure.

Also it would be nice to show the sections that an article is assigned to.

Now add some sections and some articles so there is something to show.


Step 2 Showing the Sections

Add the following into functions.php from your theme.

In the theme folder create a file called sidebar-sections.php where your kb_sections function will be called outputting an unordered and nested list of sections.

Like this, the KB sections can be shown everywhere as desired by including the sidebar.


Step 3 Showing the Articles

Add the following into functions.php from your theme.

Note: this method is necessary because an article can be linked to multiple sections.

This will generate a hierarchical permalink structure.

Like: /knowledgebase/section-slug/sub-section-slug/another-sub-section-slug/article-slug

In the theme folder then create these files: archive-knowledgebase.php, single-knowledgebase.php, content-knowledgebase.php, taxonomy-section.php.

In archive-knowledgebase.php add the following to show the sections and recent articles.

In single-knowledgebase.php add the following.

In content-knowledgebase.php add the following.

In taxonomy-section.php add the following to show a list of articles from a section.

This can be structured and styled as desired.


Example

A real life example of how this works and how it can be used: syneto.net


References

Advertisement