Multiple Page Generator – MPG Shortcodes

Below, you’ll find a detailed guide on how to add the Multiple Page Generator – MPG Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Multiple Page Generator – MPG Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Multiple Page Generator – MPG Plugin and the shortcodes it provides:

Plugin Icon
Multiple Page Generator Plugin – MPG

"Multiple Page Generator Plugin – MPG is a versatile WordPress tool designed to create multiple pages at once, streamlining content generation and enhancing your website's efficiency."

★★★☆✩ (19) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: 7.2
Included Shortcodes:
  • [mpg]
  • [mpg_match]
  • [mpg_search]

Multiple Page Generator – MPG [mpg] Shortcode

The MPG Core Controller shortcode is a crucial function that allows the generation of unique content. It normalizes attribute keys, sets a limit for results, and ensures unique rows. The shortcode also handles exceptions, logs errors, and facilitates redirection if needed. It’s a vital part of maintaining smooth and efficient website operations.

Shortcode: [mpg]

Parameters

Here is a list of all possible mpg shortcode parameters and attributes:

  • limit – sets the maximum number of results to display.
  • unique-rows – when set to ‘yes’, it ensures that the results are unique.

Examples and Usage

Basic example – The shortcode ‘mpg’ is used to generate unique pages from a CSV file. By default, it doesn’t require any parameters.

[mpg /]

Advanced examples

Setting a limit to the number of generated pages. Here, the ‘limit’ parameter is used to restrict the number of pages generated to 5. Please note that the count starts from 0, so for 5 pages, we use 6 as the limit.

[mpg limit=6 /]

Ensuring unique rows in the generated pages. The ‘unique-rows’ parameter is used to ensure that each row from the CSV file is used only once, creating unique pages. Set ‘unique-rows’ to ‘yes’ to enable this feature.

[mpg unique-rows=yes /]

Combining multiple parameters. In this example, we are setting a limit to the number of generated pages and ensuring unique rows at the same time.

[mpg limit=6 unique-rows=yes /]

PHP Function Code

In case you have difficulties debugging what causing issues with [mpg] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mpg', ['MPG_CoreController', 'mpg_shortcode']);

Shortcode PHP function:

function mpg_shortcode($atts = array(), $content = null)
    {

        try {
            if (is_admin()) {
                return false;
            }

            // normalize attribute keys, lowercase
            $atts = array_change_key_case((array) $atts, CASE_LOWER);

            if ( isset( $atts['limit'] ) ) {
                // фикс из-за того, что человек пишет лимит = 2, а получает 3 результата, ведь отсчет в массивах начинается с 0
                $atts['limit'] = (int) $atts['limit'] - 1;
            }

            $atts['unique-rows'] = isset($atts['unique-rows']) && $atts['unique-rows'] === 'yes';

            return self::mpg_shortcode_core($atts, $content);
        } catch (Exception $e) {

            $path = MPG_Helper::mpg_get_request_uri(); // это та часть что идет после папки установки WP. тпиа wp.com/xxx
            $redirect_rules = MPG_CoreModel::mpg_get_redirect_rules($path);

            if ($redirect_rules && isset($redirect_rules['project_id'])) {

                do_action( 'themeisle_log_event', MPG_NAME, sprintf( 'Exception in [mpg_shortcode]: %s', $e->getMessage() ), 'debug', __FILE__, __LINE__ );

                MPG_LogsController::mpg_write($redirect_rules['project_id'], 'error', __('Exception in [mpg_shortcode]: ', 'mpg') . $e->getMessage());
            }
        }
    }

Code file location:

multiple-pages-generator-by-porthas/multiple-pages-generator-by-porthas/controllers/HookController.php

Multiple Page Generator – MPG [mpg_match] Shortcode

The Multiple Pages Generator by Porthas shortcode, ‘mpg_match’, is used to generate multiple pages based on a dataset. This shortcode normalizes attribute keys to lowercase and adjusts the ‘limit’ attribute to match array counting, which starts from 0. In case of exceptions, it logs the error message and the redirect rules for the requested path.

Shortcode: [mpg_match]

Parameters

Here is a list of all possible mpg_match shortcode parameters and attributes:

  • limit – defines the maximum number of results to return

Examples and Usage

Basic example – The shortcode ‘mpg_match’ is used to invoke the function ‘mpg_match’ from the class ‘MPG_CoreController’. This shortcode does not require any parameters to function.

[mpg_match /]

Advanced examples

The shortcode ‘mpg_match’ can also accept parameters, or ‘atts’. For example, you can specify a limit to the number of matches the function will return. The ‘limit’ att is subtracted by 1 because array counting starts at 0.

[mpg_match limit=3 /]

Another parameter that can be used with the ‘mpg_match’ shortcode is ‘content’. This parameter allows you to specify the content that will be used within the function. Please note that the ‘content’ parameter should be a valid string.

[mpg_match content="your_content_here" /]

In addition to ‘limit’ and ‘content’, you can use any number of parameters with the ‘mpg_match’ shortcode. The function will normalize all attribute keys to lowercase and use them within the function.

[mpg_match att1="value1" att2="value2" /]

Please note that the ‘mpg_match’ shortcode will not work in the admin area of your WordPress site. It is designed to be used on the front-end only.

PHP Function Code

In case you have difficulties debugging what causing issues with [mpg_match] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mpg_match', ['MPG_CoreController', 'mpg_match']);

Shortcode PHP function:

function mpg_match($atts = array(), $content = null)
    {

        try {
            if (is_admin()) {
                return false;
            }

            // normalize attribute keys, lowercase
            $atts = array_change_key_case((array) $atts, CASE_LOWER);
            if (isset($atts['limit'])) {
                // фикс из-за того, что человек пишет лимит = 2, а получает 3 результата, ведь отсчет в массивах начинается с 0
                $atts['limit'] = (int) $atts['limit'] - 1;
            }

            return self::mpg_match_core($atts, $content);
        } catch (Exception $e) {

            $path = MPG_Helper::mpg_get_request_uri(); // это та часть что идет после папки установки WP. тпиа wp.com/xxx
            $redirect_rules = MPG_CoreModel::mpg_get_redirect_rules($path);

            if ($redirect_rules && isset($redirect_rules['project_id'])) {

                do_action( 'themeisle_log_event', MPG_NAME, sprintf( 'Exception in [mpg_match]: %s', $e->getMessage() ), 'debug', __FILE__, __LINE__ );

                MPG_LogsController::mpg_write($redirect_rules['project_id'], 'error', __('Exception in [mpg_match]: ', 'mpg') . $e->getMessage());
            }
        }
    }

Code file location:

multiple-pages-generator-by-porthas/multiple-pages-generator-by-porthas/controllers/HookController.php

Multiple Page Generator – MPG [mpg_search] Shortcode

The Multiple Pages Generator by Porthas (MPG) shortcode is a powerful tool that generates a search functionality on your WordPress site. It allows users to perform a search, limit the number of results, and specify the base URL. This shortcode also supports case sensitivity. The search results are displayed in a structured format, with each result featuring a title link and an excerpt.

Shortcode: [mpg_search]

Parameters

Here is a list of all possible mpg_search shortcode parameters and attributes:

  • s – the search string to use for querying data
  • limit – the maximum number of results to return
  • base-url – the base URL to prepend to result links
  • case_sensitive – determines if the search should be case sensitive

Examples and Usage

Basic example – The following shortcode displays the search results from the MPG plugin. It uses the ‘s’ attribute to define the search string.

[mpg_search s="example" /]

Advanced examples

Below is a shortcode that displays the search results with a limit on the number of results displayed. The ‘limit’ attribute is used to set the maximum number of results to be displayed.

[mpg_search s="example" limit=5 /]

This next example uses the ‘case_sensitive’ attribute. If this attribute is set to ‘1’, the search will be case sensitive.

[mpg_search s="example" case_sensitive=1 /]

Finally, this example uses the ‘base-url’ attribute. This attribute allows you to set a base URL for the search results. The search results will be appended to this base URL.

[mpg_search s="example" base-url="https://www.example.com/" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [mpg_search] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('mpg_search', ['MPG_SearchController', 'mpg_search_shortcode']);

Shortcode PHP function:

function mpg_search_shortcode($args)
    {
        if (class_exists('MPG_ProjectController')) {

            $search_string  = isset($args['s']) ? $args['s'] : null;
            $limit          = isset($args['limit']) ? (int) $args['limit'] : 10;
            $base_url       = isset($atts['base-url']) ? (string) $atts['base-url']  : MPG_Helper::mpg_get_base_url(true);
            $case_sensitive = isset( $args['case_sensitive'] ) && $args['case_sensitive'] === '1' ? true : false;


            $search = self::mpg_search($search_string, $limit, $case_sensitive);
            if (!isset($search['total']) || $search['total'] === 0) {
                return;
            }

            $response = '<div class="mpg-search-results">';
            $response .= '<span class="mpg-search-results-count">' . __('Total results:', 'mpg') . ' ' . $search['total'] . '</span>';
            foreach ($search['results'] as $index => $result) {

                $response .= '<div class="mpg-search-results-row">';
                $response .= '<h2 class="mpg-page-title"><a class="mpg-page-link" href="' . $base_url . $result['guid'] . '">' . $result['post_title'] . '</a></h2>' .
                    '<p class="mpg-page-excerpt">' . $result['post_excerpt'] . '</p>';
                $response .= '</div>';
                if ($index >= $limit - 1) {
                    break;
                }
            }

            $response .= '</div>';

            return $response;
        }
    }

Code file location:

multiple-pages-generator-by-porthas/multiple-pages-generator-by-porthas/controllers/HookController.php

Conclusion

Now that you’ve learned how to embed the Multiple Page Generator – MPG Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *