How To Build A Wiki Knowledge Base With WordPress

4 minutes read

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.

add-kb-articles [1]

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">';
9
10     // display entries in the section
11     $kb_args array(
12         'post_type' => 'knowledge_base',
13         'posts_per_page'=>-1,
14         'tax_query' => array(
15             array(
16                 'taxonomy' => 'section',
17                 'terms'    => $section,
18             )       ,
19         ),
20     );
21
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>';
27                 $return .=  '</li>';
28             endwhile;
29     wp_reset_postdata();
30          else :
31                 $return .= '<p>No Articles Found</p>';
32         endif;
33     $return .=  '</ul></div>';
34     endforeach;
35     return $return;
36 }
37 // Create a shortcode
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.

kb-no-css [1]

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.

1 .kb_section {
2 floatleft;
3 width280px;
4 max-width280px;
5 margin10px;
6 background-color#f5f5f5;
7 border1px solid #eee;
8 }
9 h4.kb-section-name {
10 background-color#eee;
11 margin0;
12 padding5px;
13 }
14 ul.kb-section-list {
15 list-style-typenone;
16 list-stylenone;
17 displayinline;
18 }
19 li.kb-section-name {
20 list-style-typenone;
21 displayinline;
22 }
23 ul.kb-article-list {
24 list-style-typenone;
25 list-stylenone;
26 }
27 li.kb-article-name {
28 list-style-typenone;
29 }
30 div.kb_section:nth-of-type(3n+1) {clear:left;}
31 div.kb_section:nth-of-type(3n+3) {}

This is what the result will look like on the standard Twenty Twelve theme.

style-kb [1]

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.

 

Facebook Twitter LinkedIn Telegram Pocket

Related Posts:

Do you want to add notifications to the admin panel in WordPress? Admin notifications are used by the WordPress core, themes, and plugins to display warnings, notifications, and important information for users on the screen. In this article, we will show you how to add notifications to the WordPress admin panel. Why And When Should I Use Admin Messages In WordPress? WordPress uses notifications in the admin panel to inform users of errors, warnings and messages about the successful completion ...
Would you like to turn off email notification about automatic WordPress update? By default, WordPress sends email notifications to inform you that security updates have been installed on your site. Recently, a reader asked if there was a way to disable these emails. In today’s article, we will show you how easy it is to turn off email notification of WordPress automatic updates. About Automatic WordPress Update WordPress is open source software and is supported by the developer community. ...
Would you like to remove the “WordPress site” link from the footer of your site? Recently, one of our readers asked if it was possible to remove copyrights from the footer in WordPress themes. In this article, we will show you how to remove a link for a WordPress site from the footer of your themes. The default theme in WordPress uses the footer area to display the link “Website powered by WordPress”. Many theme developers replace copyrights with their own, so the link looks like “T...