Enhancing features of the questions plugin
In the previous sections, we illustrated how to quickly adapt WordPress into different kind of implementations by customizing its core features. However, I had to limit the functionality to the most basic level in order to keep this chapter short and interesting for the beginners. If you are willing to improve it, you can try other new features of such an application. Here, we will be looking at some of the enhancements to this plugin and how we can use core WordPress features to implement them.
Customizing the design of questions
This is one of the major requirements in such an application. Here, we have a very basic layout and it's difficult to know whether this is a question or just a normal post. Consider the following screenshot for a well-designed question interface:
Remember that we customized the comments list for adding new options. Similarly, we can customize the design of questions to create an interface such as the previous screenshot by using a separate template file for the questions custom post type. We have to create a file called single-wpwa_question.php
and change the design and functionality as we want.
Categorizing questions
Categories allow us to filter the results and limit it to a certain extent. It's an essential feature in the question-answer application so that users can directly view questions related to their topic instead of browsing all the questions. WordPress provides categories by default. However, these categories are mainly intended for posts. Therefore, we have to use custom taxonomies to create categories for custom post types such as questions. More details about taxonomies will be discussed in the following chapters.
Approving and rejecting questions
Currently, our application can post questions without any approval process. However, this is not the ideal implementation as it can create a lot of spam questions. In a well-built application, there should be a feature to approve/reject questions when needed. This feature can be easily built with WordPress admin lists. We have a list of questions in the backend, and we can use the Bulk Actions dropdown on top to add custom actions and implement this feature.
Adding star rating to answers
The author who asked the question can mark the answers as correct or incorrect. However, there can be scenarios where answers are not marked as correct are more suitable than answers marked as correct. Therefore, we can introduce star rating features to answers so that public can rate the answers. The person who looks for the answer can consider the rating before choosing answers. Implementation of this requirement is similar to the functionality of the Mark as Correct button. We have to get a js
plugin for star rating and integrate to the interface through the wpwa_comment_list
function. Then we can use AJAX to mark the status of answers.
We have looked at some of the possible enhancements to such an application. You can think of many more such functionalities and implement them in your own version.
In the following chapters, we'll see the limitations in this approach in complex web applications and how we can organize things better to write quality and maintainable code.