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:

Selling WordPress plugins can be a lucrative business for developers and entrepreneurs. WordPress is one of the most popular content management systems, powering millions of websites worldwide. By creating and selling WordPress plugins, you can tap into this v...
To install WordPress on Docker, follow these steps:Choose a directory on your computer where you want to store your WordPress files.Open a terminal or command prompt and navigate to the chosen directory.Create a new directory for your WordPress installation us...
To get the base URL of a website in Jinja2, you can make use of the url_for function provided by Flask. Here&#39;s how you can achieve it:First, make sure you have Flask installed and a Flask application set up. In your Jinja2 template file, you can use the ur...