How to Generate a List of MPG Pages?

Introduction

One of the biggest advantages of using the MPG plugin is the possibility to generate filtered lists of data from your Source File. This helps to generate tables of factual content, in-links, etc. The most popular example would be generating a clickable list of all states in a country or cities in a state.

To do just that, we will:

  • head over to your MPG project, and click on the “Shortcode” tab at the top of the page.
  • Scroll down to “Generate list”.
  • Here we can set up the filter and criteria for the generated list. For example, if you use our “US cities” template and would like to generate a clickable list of all cities in Cuyahoga County, in the state of Ohio, you would specify the condition as state_name = Ohio AND county_name = Cuyahoga.
  • The shortcode below will be generated which can be previewed

There are many ways to customize the list by:

  • Limiting the number of generated results using the “Limit” parameter.
  • Return results in a random order, ascending or descending using the “Direction” parameter.
  • Generating Nested Lists for hierarchical content such as Country > State > City type of pages, where each project generates a list of subsequent filtered results.
  • How Do I Split My Generated List into Columns?

List of Attributes

project-id

(required, integer) – uses the project ID from which data is retrieved

Example: project-id="1"

where

(optional, text or shortcode)  – uses single or multiple expressions separated by semicolon “;”.

Used to specify filter conditions of the generated list. A static text such as “California”, for example, or a shortcode such as {{mpg_state}}. Regular expression syntaxis can be used in the PCRE format.

Format: where=”mpg_header=value”

  • Example 1: where=”mpg_city=Springfield” – returns all rows where column  mpg_city contains the value Springfield
  • Example 2: where=”mpg_city=^Ca” – returns all rows where column mpg_city contains values starting with “Сa”, such as Canberra
  • Example 3: where=”mpg_city=burgh” – returns all rows where column mpg_city contains values ending with “burgh”, such as Edinburgh
  • Example 4: where=”mpg_state={{mpg_state}}” – returns all rows where column mpg_city contains value equal to current value of mpg_state per given page. If a user opens the page for the city of “San Diego”, which is in state California, then the shortcode will return all rows where state = California. Therefore if a user opens a page for the city of “Cleveland” which is in Ohio, then the same shortcode will return all rows for Ohio.
  • Example 5: mpg_city=york finds all rows in which mpg_city contains “york” (as LIKE(%york%) in MySQL). Result – https://prnt.sc/vr0w4g
  • Example 6: mpg_city=^york$ finds all rows, where cell mpg_city has an exact match with “york”. Result – https://prnt.sc/vr0uh3
  • Example 7: mpg-city=^{{mpg_city}} finds all rows where mpg_city starts with a string that matches the city related to the currently requested URL. It is not a constant value because {{mpg_city}} will change when you visit another generated page.

operator

(optional, string) – available: 'or' (default) and 'and'

Used for specifying additional conditions for where. Examples:

  • Example 1: where=”mpg_city=^Ca; mpg_country=Australia” operator=”and” - all rows are selected where mpg_city starts with Ca, while mpg_country in the same row is "Australia".
  • Example 2: where=”mpg_socks_size=Medium; mpg_socks_size=Large” operator=”or” - all rows are selected where mpg_socks_size is Medium or Large.

limit

(optional, integer) – Used for limiting the number of returned results. Example use: limit=”5”. If the limit is more than the returned results, the returned lists won't be affected.

order-by

(optional, string) – allows specifying a column from the data source file to sort by. Used paired with the 'direction' attribute.

Example 1: order-by=”mpg_city”

direction

(optional, string) – allows specifying one of the three sorting options: 

  • acs – for ascending sorting. Requires order-by attribute
  • desc – for descending sorting. Requires order-by attribute
  • random – randomized sorting

unique-rows

(optional, string) - possible values: "yes" or "no".
Default value "no"
Use unique-rows="yes" in case, you would like to have no duplicates in the shortcode response.

For example, if the source file contains 100 rows with city New York, and you render list with cities, unique-rows="yes" attribute will skip duplicate rows, and render just the first row, instead of 100

Examples:

  • Example 1:  order-by=”mpg_city” direction=”asc” – sorts by city names from A to Z
  • Example 2:  order-by=”mpg_city” direction=”desc” – sorts by city names from Z to A
  • Example 3:  direction=”random” – randomizes returned values. After each refresh, unless the cache is enabled, a new order is generated.

For further help, you can watch this short tutorial video showing how you can create links for your generated pages:

Let your imagination run wild by creating nests of templates! You can have a template made for countries, then within each generated page have a generated list of states/provinces, and within that, a generated list of cities, and within that, a generated list of Mayors and each page containing the biography of each mayor. Impressed yet?! Go on and try this yourself!

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us