MakeStories (for Google Web Stories) Shortcodes

Below, you’ll find a detailed guide on how to add the MakeStories (for Google Web Stories) 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 MakeStories (for Google Web Stories) Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the MakeStories (for Google Web Stories) Plugin and the shortcodes it provides:

Plugin Icon
MakeStories (for Google Web Stories)

"MakeStories (for Google Web Stories) is a handy WordPress plugin that enables the creation and publishing of engaging Google Web Stories directly from your WordPress dashboard. Upgrade your storytelling with MakeStories!"

★★★★✩ (28) Active Installs: 4000+ Tested with: 6.2.3 PHP Version: 5.6
Included Shortcodes:
  • [ms_get_published_post]
  • [ms_get_post_by_category]
  • [ms_get_single_post]
  • [ms_get_single_widget]

MakeStories (for Google Web Stories) [ms_get_published_post] Shortcode

The MakeStories Helper shortcode, ‘ms_get_published_post’, retrieves and displays published posts. It fetches the default number of posts per page, counts the published posts, and presents them in a designed layout. The shortcode uses AJAX to dynamically load more posts, providing an interactive user experience. It also handles scenarios when no stories are found, displaying an appropriate message.

Shortcode: [ms_get_published_post]

Examples and Usage

Basic example – Displays the published posts using the default configuration.

[ms_get_published_post /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'ms_get_published_post', 'ms_get_published_post_via_shortcode' );

Shortcode PHP function:

function ms_get_published_post_via_shortcode() {
    $default_posts_per_page = get_option( 'posts_per_page' );
    $getAjaxUrl =  admin_url('admin-ajax.php');
    $postCount = wp_count_posts(MS_POST_TYPE);
    $postCount = $postCount->publish;
    $config = ms_get_options();
    $design = isset($config['design']) ? $config['design'] : "1";
    ob_start();
    ?>
    <section class="ms-default-stories">
    <?php if ($postCount > 0) { ?>
    <div id="ajax-posts" class="ms-stories-group row" data-posts="<?php echo esc_attr($default_posts_per_page); ?>" data-ajax="<?php echo esc_attr($getAjaxUrl); ?>">
        <?php
        $postsPerPage = $default_posts_per_page;

        $args = [
            'post_type' => MS_POST_TYPE,
            'posts_per_page' => $postsPerPage,
            'post_status' => 'publish',
        ];

        $loops = get_posts($args);
        $postChunks = array_chunk($loops,8);
        foreach($postChunks as $key=>$value) {
            ?>
            <div class="ms-grid stories-showcase-block <?php if ($design == "2") { echo "design-2"; } else { echo "design-1"; } ?>" id="listing-grid" data-design="<?php echo $design; ?>">
            <?php
                foreach($value as $index=>$post) {
                    include mscpt_getTemplatePath("prepare-story-vars.php");
                    if ($design == "2") {
                        include mscpt_getTemplatePath("listing-story-grid.php");
                    } else {
                        include mscpt_getTemplatePath("listing-story-masonry.php");
                    }
                }
            ?>
            </div>
            <?php
        }
        ?>
    </div>
    <div id="d-one" style="display: none;"></div>
        <?php if ($postCount > $postsPerPage) { ?>
        <div class="ms-load-more-wrap">
            <span id="ms-loading-spinner"></span>
            <a id="more_posts">Load More</a>
        </div>
    <?php
        }
    ?>
    <div id="script-block">
        <?php require_once mscpt_getTemplatePath("story-player-model.php"); ?>
    </div>
    <?php } else { ?>
            <p class="no-stories">No Stories Found</p>
    <?php } ?>
</section>
<?php
return ob_get_clean();
}

Code file location:

makestories-helper/makestories-helper/shortcode.php

MakeStories (for Google Web Stories) [ms_get_post_by_category] Shortcode

The MakeStories-Helper plugin shortcode, ‘ms_get_post_by_category’, is designed to fetch and display posts from a specific category. Using the ‘category_id’ attribute, it retrieves posts from the defined category. The function ‘ms_get_post_by_category’ queries posts based on the category ID, returning all published posts. The results are then chunked into groups of eight, ready for display. The design layout is determined by the ‘design’ configuration setting.

Shortcode: [ms_get_post_by_category]

Parameters

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

  • category_id – Identifier for the category of posts to be displayed.

Examples and Usage

Basic example – A simple usage of the shortcode to fetch posts by a specific category ID.

[ms_get_post_by_category category_id=3 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'ms_get_post_by_category', 'ms_get_post_by_category' );

Shortcode PHP function:

function ms_get_post_by_category($attr) {
    $default_posts_per_page = get_option( 'posts_per_page' );
    $getAjaxUrl =  admin_url('admin-ajax.php');
    $cat_id = $attr['category_id'];
    $int_cat = (int)$cat_id;
    $term = get_term($int_cat,MS_TAXONOMY);
    $config = ms_get_options();
    $design = isset($config['design']) ? $config['design'] : "1";
    $args = [
        'post_type' => MS_POST_TYPE,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'offset'=> 0,
        "tax_query" => array(
            array(
                "taxonomy" => MS_TAXONOMY,
                "field" => "term_id",
                "terms" =>  $int_cat
            ))
    ];
    // $loop = new WP_Query($args);
    $loops = get_posts($args);
    $postChunks = array_chunk($loops,8);
    ob_start();
    require(mscpt_getTemplatePath('ms-post-by-category.php'));
    
    return ob_get_clean();
}

Code file location:

makestories-helper/makestories-helper/shortcode.php

MakeStories (for Google Web Stories) [ms_get_single_post] Shortcode

The MakeStories Helper shortcode is a powerful tool for fetching and displaying single posts. It uses the ‘ms_get_single_post’ shortcode to retrieve a specific post based on its ID. This shortcode accepts the ‘post_id’ parameter, finds the corresponding post in the database, and displays it according to the chosen design. The design can be either ‘1’ (default) or ‘2’, affecting the layout of the displayed post.

Shortcode: [ms_get_single_post]

Parameters

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

  • post_id – Specific identification number of the post you want to display.

Examples and Usage

Basic example – Displays a single post using the post’s ID as an attribute.

[ms_get_single_post post_id=1 /]

Advanced Examples

Displaying a single post by referencing both the post type and the post ID. The post will first try to load by ID, but if not found, it will try to load by post type.

[ms_get_single_post post_type="post" post_id=1 /]

Displaying a single post by referencing the post type, post ID, and number of posts. The post will first try to load by ID, but if not found, it will try to load by post type. The number of posts attribute will determine how many posts are displayed.

[ms_get_single_post post_type="post" post_id=1 numberposts=1 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'ms_get_single_post', 'ms_get_single_post_via_shortcode' );

Shortcode PHP function:

function ms_get_single_post_via_shortcode($attr) {
    $args = [
        "post_type" => MS_POST_TYPE,
        "numberposts" => -1
    ];
    $posts = get_posts($args);
    $config = ms_get_options();
    $design = isset($config['design']) ? $config['design'] : "1";
    ob_start();
    foreach ($posts as $post){
        $postId = $post->ID;
        if($postId == $attr['post_id']) {

            include mscpt_getTemplatePath("prepare-story-vars.php");
            if ($design == "2") {
                require(mscpt_getTemplatePath('ms-single-post.php'));
            } else {
                require(mscpt_getTemplatePath('ms-single-masonry-post.php'));
            }
        }
    }
    return ob_get_clean();
}

Code file location:

makestories-helper/makestories-helper/shortcode.php

MakeStories (for Google Web Stories) [ms_get_single_widget] Shortcode

The MakeStories Helper shortcode, ‘ms_get_single_widget’, retrieves and displays a specific widget. It does this by accessing the WordPress post meta data for a given widget ID. The PHP function ‘ms_get_single_widget_via_shortcode’ loops through all the posts, matches the widget ID, and renders the widget using the ‘ms-single-widget.php’ template.

Shortcode: [ms_get_single_widget]

Parameters

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

  • widget_id – The unique identifier of the specific widget

Examples and Usage

Basic example – Display a single widget with a specific ID using the shortcode.

[ms_get_single_widget widget_id=5 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'ms_get_single_widget', 'ms_get_single_widget_via_shortcode' );

Shortcode PHP function:

function ms_get_single_widget_via_shortcode($attr) {
    $args = [
        "post_type" => MS_POST_WIDGET_TYPE,
        "numberposts" => -1
    ];
    $posts = get_posts($args);
    ob_start();
    foreach ($posts as $post){
        $postId = $post->ID;
        if($postId == $attr['widget_id']) { 
            $meta = get_post_meta($postId);
            require(mscpt_getTemplatePath('ms-single-widget.php'));
        }
    }
    return ob_get_clean();
}

Code file location:

makestories-helper/makestories-helper/shortcode.php

Conclusion

Now that you’ve learned how to embed the MakeStories (for Google Web Stories) 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 *