How to Use the Template Page in MPG for Programmatic SEO
In this article
The Template Page in MPG acts as a blueprint for generating multiple pages from a single design. The plugin pulls dynamic data from a source file, such as a CSV or Google Sheet, and uses this data to populate variables within your template. This allows you to create thousands of unique pages quickly.
Your template can be set up using a standard WordPress page, a post, or even a custom post type. This flexibility allows you to generate the type of content that fits your specific SEO strategy.
Key Elements of the Template Page:
- Dynamic Variables: Used to insert data from your source file.
- Conditions: Control when specific parts of the template should appear.
- Static Content: The static elements that remain consistent across all generated pages.
Setting Up the Template Page
Insert Dynamic Variables:
MPG uses a simple format to insert dynamic content from your source file. The format is {{mpg_<column name>}}
, where <column name>
represents the header from your data source (e.g., CSV or Google Sheet). These placeholders will be automatically replaced with the actual values when generating pages.
- For example, if you have a column named "location" in your data source, you would use
{{mpg_location}}
in your template to dynamically insert the location.
Using Automatically Mapped Columns
MPG provides automatic mapping for certain columns from your data source. This feature allows you to easily assign specific attributes to your generated pages without additional configurations.
featured_image
Column:
If you include a column namedfeatured_image
in your data source, MPG will automatically map the URL or path in this column to set the featured image of the generated pages.featured_image_alt
Column:
This column is used to assign the "alt text" for the featured image. If you add this column and include alt text values, MPG will automatically set these values as the "alt" attribute for each featured image. Alt text is essential for accessibility and can also help with SEO.
Additionally, you can reference other columns dynamically within thefeatured_image_alt
values. Simply use the dynamic variable format{{mpg_<column name>}}
to pull in values from other columns. For example, if you have a column named "location," you can set an alt text value likeBeautiful scenery in {{mpg_location}}
to dynamically generate context-rich alt text for each image.modified_date
Column:
By including amodified_date
column in your data source, MPG can set the last modified date for each generated post. This is especially useful when your content changes regularly and you want to reflect the actual modification date.- To make use of this feature, you need to select the option "Update individual dates on sync" from the Update Date on Data Change dropdown (as shown in the image above). This ensures that each page's modification date is updated based on the values in the
modified_date
column. - Your source file must contain
modified_date
column as per the screenshot above and the corresponding value will be used as a modified date for each generated page each time the data is fetched.
- To make use of this feature, you need to select the option "Update individual dates on sync" from the Update Date on Data Change dropdown (as shown in the image above). This ensures that each page's modification date is updated based on the values in the
{{mpg_url}}
is a restricted tag that automatically renders the URL of a virtual page. Do not use"url"
as a value for any columns in your dataset because this value is reserved for this usage.
Here’s an example of how to use{{mpg_url}}
in an MPG shortcode:[mpg project-id="1" limit="5"] <div> <h2>{{mpg_hotel_name}}</h2> <p>{{mpg_description}}</p> <p>Rating: {{mpg_rating}} stars</p> <p>Price per night: ${{mpg_price_per_night_usd}}</p> <a href="{{mpg_url}}" style="text-decoration: none; color: blue;">Book Now</a> </div> [/mpg]
In this example, the
{{mpg_url}}
tag is used within an MPG shortcode to automatically generate the URL for the virtual page of each hotel. The Book Now link will direct users to the corresponding page generated by MPG.
đź“ť Note: Some themes may not display featured images on pages or posts, meaning MPG-generated pages won't either, even if the source file includes them. To verify, test a physical page with a featured image. Here's a guide that shows how to enable featured images for the pages Neve theme as an example.
Build the Template with Your Preferred Page Builder:
You can design your template using any page builder you prefer, including the WordPress Block Editor (Gutenberg), Elementor, Divi, Beaver Builder, or others. This flexibility allows you to create templates that match your design requirements and are optimized for SEO.
- Just insert the dynamic variables and conditional shortcodes directly into the page builder content, such as text blocks, headings, or image elements, depending on your chosen builder.
Dynamic Content Builder Features
Visibility Conditions
MPG includes a powerful feature for controlling the visibility of specific elements on your generated pages. This feature allows you to display or hide content based on conditions set from your data source. It’s accessible as a shortcode, a section within the Elementor editor, and in the Block Editor.
You can define visibility conditions using a shortcode, an Elementor widget section, or a Block Editor section. Let’s look at each method in detail:
1. Using Shortcodes: [mpg-if]
The [mpg-if]
shortcode lets you conditionally display or hide content based on the dataset values. Here are the details:
Available Attributes:
- column: The column to check for a condition.
Example:column="population"
- value: The value to check against the column.
Example:value="1000"
You can also use dynamic variables here to compare against the current page’s value. For example, usingvalue="{{mpg_country}}"
will compare the column with the value of the country displayed on the current page, ensuring the content is shown only when there is a match. - operator: The comparison operator. Available options are:
has_value
– Check if the column has any value.equals
– Check if the column’s value is equal to the given value.not_equals
– Check if the column’s value is not equal to the given value.empty
– Check if the column has no value.contains
– Check if the column’s value contains the specified substring.not_contains
– Check if the column’s value does not contain the specified substring.greater_than
– Check if the column’s value is greater than the specified value.gte
– Check if the column’s value is greater than or equals the specified value.less_than
– Check if the column’s value is less than the specified value.lte
– Check if the column’s value is less than or equal to the specified value.regex
– Check if the column’s value matches a regular expression.
Multiple Conditions: You can specify up to 5 conditions using additional attributes like column1
, value1
, operator1
, and so on.
Logic Grouping: Determine how multiple conditions should be grouped using logic="all"
(AND) or logic="any"
(OR).
Where Attribute: A simplified method to define conditions in a single string format, such as where="column1=value1;column2!=value2;column3>value3"
.
Example Shortcodes:
<div>[mpg-if column="country" value="Romania" operator="equals" logic="all"] Content to display if the country is Romania. [/mpg-if] </div><div>[mpg-if where="country=Romania;population>1000"] Content to display if the country is Romania and the population is greater than 1000. [/mpg-if]</div> <br>
2. Visibility Conditions in Elementor
All Elementor widgets have a dedicated section for MPG Visibility Conditions under Advanced → MPG Visibility Conditions. This section includes a condition builder where you can set visibility rules based on the data from your source file.
3. Visibility Conditions in Block Editor
In the WordPress Block Editor, every block also has a section called MPG Visibility Conditions with a built-in condition builder. This section allows you to create conditions similar to those in the Elementor editor.
Loop Builder
The Loop Builder in MPG allows you to create dynamic content loops based on your project data. This feature is essential when you need to generate multiple instances of content based on conditions or data-driven logic. The Loop Builder supports both shortcodes and the WordPress Block Editor, providing flexible ways to manage repeated content.
The Loop Builder uses the [mpg]
shortcode to create loops from your data source. All previous visibility condition attributes, such as columns, values, operators, and logical grouping, work the same way within the loop context.
Using the [mpg]
Shortcode for Loops
The [mpg]
shortcode enables you to repeat sections of content dynamically. Let’s look at the available attributes:
Available Attributes:
- Multiple Conditions:
You can specify up to 5 conditions using attributes likecolumn1
,value1
,operator1
, and so on, to filter which rows are looped through.- Example:
column1="country" value1="Romania" operator1="equals"
- Example:
- Logic:
Determines how multiple conditions should be grouped. Uselogic="all"
(acts like AND) orlogic="any"
(acts like OR). - Where:
A simplified method to define conditions in a single string, such aswhere="column1=value1;column2!=value2;column3>value3"
. Supported operators include=
,!=
,>
,<
,<
,>=
,<=
You can also use dynamic variables here to compare against the current page’s value. For example, usingvalue="{{mpg_country}}"
will compare the column with the value of the country displayed on the current page, ensuring the content is shown only when there is a match. - Limit:
Sets the maximum number of results to return. If not specified, all results are displayed. - Unique Rows:
Whether to return only unique rows. Acceptsyes
orno
. The default isno
. - Project-ID:
The ID of the project to query from. This allows querying across different projects. - Order-By:
The column to order the results by. Useful when you want to sort the looped content. - Direction:
The direction for ordering results. Acceptsasc
,desc
, orrandom
.
Example Shortcode Usage:
[mpg column1="country" value1="Romania" operator1="equals" limit="5" order-by="population" direction="desc"] Content to repeat for the first 5 rows where the country is Romania, ordered by population in descending order. [/mpg]
Loop Builder in Block Editor
In the WordPress Block Editor, the Loop Builder is available as a block called MPG Loop Block. This block enables you to dynamically repeat content based on conditions and loop settings. Here are the key features:
Key Features of the Loop Block:
- Flexible Content Inclusion:
You can insert any type of content blocks within the Loop Block, providing flexibility for designing repeated sections. For example, you can insert headings, images, buttons, or other blocks that will be repeated based on the loop conditions. - Content Repetition:
The Loop Block automatically repeats its inner content based on the Limit setting. This is useful for creating lists, grids, or any other repeated layout you need. - Two Main Settings Areas:
- Filters: This section allows you to define conditions that control which data is included in the loop. You can set up column-based filters to refine which rows are used in the loop.
- Loop Settings: Here, you can configure the repetition behavior, including the number of repetitions through the Limit field. For example, setting the limit to
10
will repeat the block’s content for the first 10 filtered rows.
- Preview Functionality:
A Preview Loops button is available to let you see how the looped content will appear on the frontend. This live example helps you confirm the final appearance of the content before publishing.