If you work with the Wapkiz or Wapaxo platforms, you already know they offer many tools to build websites and blogs quickly. But did you know that, besides JavaScript, there's a powerful native variable system that can make your site much more dynamic and intelligent?
Many developers stick to the basic tags, but mastering Wapkiz's native variables is what separates a common site from a truly interactive one. In this article, we'll dive deep into this feature, showing you how it works and how to apply it with a practical and highly useful example: creating a related posts section.
In this article, you'll learn:
- What are variables and why are they important?
- The special syntax for declaring and using variables in Wapkiz
- Practical Tutorial: Creating a dynamic related posts list
- Step 1: Capture the current post's category
- Step 2: Use the category to filter a new post list
What Are Variables? A Quick Reminder
Before we get into the specific Wapkiz syntax, let's review the basics. Think of a variable as a box with a label. You can put information inside the box (the value) and give it a name (the label). Later, when you need that information, you just call the box by its label.
Every programming language uses variables to temporarily store data, such as a user's name, the result of a calculation, or, as we'll see, a post's category.
The Special Wapkiz Variable Syntax
Wapkiz has its own way of declaring and using variables that works directly within the platform's codes and tags.
1. Declaring a Variable
To "create our box" and store information, we use the following structure:
:*var:VARIABLE_NAME=VALUE:
Note: Remove the asterisk
Breaking down the code:
- The colons (
:
) at the beginning and end indicate that this is a special Wapkiz code. var
is the command to declare a variable.VARIABLE_NAME
is the label you choose. Use descriptive names without spaces.=
is the assignment operator.VALUE
is the information you want to store.
2. Using a Variable
Now that the information is stored, how do we display it on the page? We use the call code:
:v1:VARIABLE_NAME:
Breaking down the code:
v1
is the command to "retrieve" the variable's value.VARIABLE_NAME
is the label of the variable you want to use.
Practical Tutorial: Creating a Related Posts List
This is one of the smartest uses for native variables. The goal is to display, at the end of a post, a list of other articles that belong to the same category as the one the reader is currently viewing.
Step 1: Capture and Store the Current Post's Category
First, you need to edit the layout code for your post page. Inside the main loop that displays the post's content, we'll declare a variable to store its category.
The code will look something like this:
[blog]to=:to-id:||
...
:*var:category=%*category%:
...
[/blog]
What's happening here?
[blog]to=:to-id:||...[/blog]
is the Wapkiz tag that fetches and displays the current post's content.%*category%
is a Wapkiz system variable. It automatically holds the name of the category for the post being displayed.- By writing
:*var:category=%*category%:
we are saying: "Create a variable namedcategory
and assign it the value that the system already knows is this post's category."
Step 2: Use the Variable to Filter a New List of Posts
Now, still on the same page, we'll add a new list of posts. This is where'' we'll use our variable to filter the results.
[blog]cat=:v1:category:, o=u, l=6||
%title%
[/blog]
Analyzing the final play:
cat=:v1:category:
is the crucial part. Instead of a fixed name, we use the variable we created. Wapkiz will dynamically replace it with the correct category.o=u, l=6
are extra parameters:o=u
sorts by update date, andl=6
limits the list to 6 items.
Conclusion
Mastering native variables in Wapkiz and Wapaxo is a key step toward creating more professional and personalized websites. With them, you can add logic to your site without needing complex JavaScript.
Have any questions? Have another idea for using variables? Leave a comment below!
0 Comments
Leave a Reply