Are you looking for a way to add a support / documentation section on your site? Want to find out the best way to add a wiki knowledge base to your WordPress site? In today’s article, we will show you how to create a wiki knowledge base in WordPress without plugins.
We will pass stage by stage of the embodiment of the conceived.
Note: Before you begin, please make a full backup of your WordPress site.
First of all, you need to install and activate the Knowledgebase CPT plugin . This simple plugin creates a random entry type called knowledge_base and a taxonomy called section .
This will allow you to easily add your wiki articles and organize them into sections.
Once you have created several articles and a section, you will need to display them on your site. It is here that will have to tinker with the code.
You should start by adding a snippet of code to the functions.php file of your theme or to the plugin for the WordPress site :
1 |
function devise_knowledgebase() { |
2 |
// We get knowledge base sections |
3 |
$kb_sections = get_terms( 'section' , 'orderby=name&hide_empty=0' ); |
4 |
// For each section of the knowledge base |
5 |
foreach ( $kb_sections as $section ) : |
6 |
$return .= '<div class="kb_section">' ; |
7 |
// display section name |
8 |
$return .= '<h4 class="kb-section-name"><a href="' . get_term_link( $section ) . '" title="' . $section ->name . '" >' . $section ->name . '</a></h4><ul class="kb-articles-list">' ; |
10 |
// display entries in the section |
12 |
'post_type' => 'knowledge_base' , |
16 |
'taxonomy' => 'section' , |
22 |
$the_query = new WP_Query( $kb_args ); |
23 |
if ( $the_query ->have_posts() ) : |
24 |
while ( $the_query ->have_posts() ) : $the_query ->the_post(); |
25 |
$return .= '<li class="kb-article-name">' ; |
26 |
$return .= '<a href="' . get_permalink( $the_post ->ID ) . '" rel="bookmark" title="' . get_the_title( $the_post ->ID ) . '">' . get_the_title( $the_post ->ID ) . '</a>' ; |
31 |
$return .= '<p>No Articles Found</p>' ; |
33 |
$return .= '</ul></div>' ; |
38 |
add_shortcode( 'knowledgebase' , 'devise_knowledgebase' ); |
This code prints all articles from the knowledge base to the section in which they are added.
Next, all you need to do is create a new page in WordPress and add a knowledgebase shortcode to it . Save your page and go to it.
All this does not look very decent at the moment, but we can add some styles. You can use the following CSS as a starting point and make changes that will be combined with the overall style of your site.
Paste the following code into your theme’s style.css file.
6 |
background-color : #f5f5f5 ; |
7 |
border : 1px solid #eee ; |
10 |
background-color : #eee ; |
15 |
list-style-type : none ; |
20 |
list-style-type : none ; |
24 |
list-style-type : none ; |
28 |
list-style-type : none ; |
30 |
div.kb_section:nth-of-type( 3 n+ 1 ) { clear : left ;} |
31 |
div.kb_section:nth-of-type( 3 n+ 3 ) {} |
This is what the result will look like on the standard Twenty Twelve theme.
By default, your sections will be displayed in alphabetical order. However, if you want to change the sorting order of partitions, then this can be done by installing the Custom Taxonomy Order NE plug-in . It will allow you to drag your sections in the correct order.