Manual theme template integration

By default, the standard way to integrate user reviews into the theme is to use automatic, built-in method to override the comments template and to add review block overview at the end of the post/page content.

But, that is not something that can work in every situation. In some cases, you will need to manually integrate reviews into theme templates. For this, plugin has 2 functions: gdrts_ur_show_reviews_block and gdrts_ur_show_reviews_overall.

Let’s see how this can be done. In this example, we will create a custom page template for use with the page post type. You need to enable user reviews and configure it. Here is the screenshot of the Page post type for User Reviews:

User Reviews Settings for Page
User Reviews Settings for Page

So, now that User Reviews are enabled for the Page post type, we need a template.

Here is how basic custom page template looks like for the TwentySixteen theme:

<?php
/**
 *  Template Name: Example Template
 */

get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php

        while (have_posts()) : the_post();

            get_template_part('template-parts/content', 'page');

        endwhile;

        ?>

    </main>

    <?php get_sidebar( 'content-bottom' ); ?>
</div>

<?php get_sidebar(); ?>
<?php get_footer();

On the line 14, theme loads the page content template. So, we want to add user reviews after this line, so the modified template with our added functions looks like:

<?php
/**
 *  Template Name: With User Reviews
 */

get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php

        while (have_posts()) : the_post();

            get_template_part('template-parts/content', 'page');

            // display user review overall reviews //
            gdrts_ur_show_reviews_overall();

            // display user reviews and review form //
            gdrts_ur_show_reviews_block();

        endwhile;

        ?>

    </main>

    <?php get_sidebar( 'content-bottom' ); ?>
</div>

<?php get_sidebar(); ?>
<?php get_footer();

Now, when you create new page, just select this newly created template from the Template dropdown, and that page will show user reviews.

0
0
114
Rate this article

You are not allowed to rate this post.

Comments

Leave a Reply