The template tags of Affiliate Product Reviews

What are template tags?

Template tags are special PHP functions of WordPress to display information dynamically. They are used in the themes template files. The WordPress Codex says:

Template tags are used within your blog’s Templates to display information dynamically or otherwise customize your blog, providing the tools to make it as individual and interesting as you are.

For the Affiliate Product Reviews plugin special template tags have been developed, which you can use in your template files. All these functions start with the prefix ri_. So for example ri_get_the_price. All function which start with ri_get_the return the output while all functions which start ri_the will echo the output. So, all template tags are available in two versions, one will return the output and one will echo the output instantly.

The template tags

Below, you will find all template tags, which Affiliate Product Reviews provide.

The Rich Snippet

ri_get_the_rich_snippet()
ri_the_rich_snippet()

Outputs the rich snippet. Optionally you can provide a post ID, so the rich snippet of a specific review will be output. If you do not provide a post ID, the rich snippet of the current review will be returned.

The Shop Link

ri_get_the_shop_link()
ri_the_shop_link()

Returns the masked link to the affiliate product. You can optionally provide a post ID, so the link of this specific review will be returned. Otherwise, the current product link will be returned. You can secondly provide a link text. If you do not provide a link text, the text string, which is provided in the settings tab “Text & Strings” will be used.

Example:

<?php 
ri_the_shop_link( $post_id, 'Buy the product' ); 
?>

The prices

ri_get_the_price()
ri_the_price()

Returns the price of a product. A post ID can be provided optionally. As a second parameter, you can specifiy, which price you want to output. The standard is ri_price, which returns the sales price. ri_recommended_price will return the list price.

Example: Output the list price for the current review.

<?php 
ri_the_price( get_the_ID(), 'ri_recommended_price' ); 
?>

The data sheets

ri_get_the_datasheet()
ri_the_datasheet()

Will return the data sheet of the current review. If you provide a post ID, the data sheet of this specific review will be returned. As a second parameter, you can provide the ID of a specific data sheet frame, you want to return. If you do not provide such an ID, all data sheets will be combinded and outputted. You can define several data sheet frames on the plugins settings page. If you for example run a website with reviews about TVs & computers, you could create two data sheet frames, one, you will use for TVs and another one for computers. If you have a TV which is also a computer, you might want to fill out both data sheets. In this case, these data sheets would be outputted together in one sheet. But with the second parameter, you can now define, which sheet shall be outputted (and by doing so, you could seperate these sheets).

Example: Output the data sheet “2” of the current review.

<?php 
ri_the_datasheet( get_the_ID(), 2 ); 
?>

The Pro & Contra

ri_get_the_pro_contra()
ri_the_pro_contra()

Returns the pro and contra list of a review. You can provide a $post_id as a first parameter. As a second parameter you can define, whether you want to return the pro and the contra list (both), only the pro list (pro) or only the contra list (contra).
Example: Return the current pro list

<?php
ri_the_pro_contra( get_the_ID(), 'pro' );
?>

The ratings

ri_get_the_ratings()
ri_the_ratings()

Outputs the ratings for the current post. There are several parameters which can be used:

Parameter Meaning
$post_id (int) Provides the ID of the review. Standard: the current review
$show_rating (bool) If you set this value false the numerical rating (for example: (4/5)) will not be shown. If it is set true (standard) the rating will be shown.
$type (string) bar shows the ratings as a bar graph (standard). stars will show it as stars.
$display_average (bool) true (standard): The average rating (out of the several ratings you may provide) will be calculated and shown. false: The average rating will not be shown.
$rating_id (mixed): As with the data sheets, you can provide several rating systems to seperate different product types. The value all will display all ratings, which you have provided. Or you specify the ID of a specific rating system, to display only this system.

The product images

The single image

ri_get_the_image()
ri_the_image()

Returns a single product image. Several parameters can be defined:

Parameter Meaning
$post_id (int) Provides the ID of the review. Standard: the current review
$image (int) The ID of the image, which you want to return. The images are saved as an array in the custom field ri_images. Here you can provide the array key. To return the first image, you will use the ID 0, for the second 1 and so on.
$type (string) bar shows the ratings as a bar graph (standard). stars will show it as stars.
$size (string/array) Image size. Either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32).
$icon (bool): Use a media icon to represent the attachment. Standard is false.
$attr (string/array) Query string or array of attributes. See the WordPress Codex for more information.

All product images

ri_get_the_images()
ri_the_images()

Returns all product images:

<?php 
ri_the_images( $post_id = null, $size = 'thumbnail', $icon = false, $type = 'list', $args = array() ); 
?>

For $post_id, $size, $icon and $args see ri_get_the_image(). The $type-parameter specifies the return type. Values are:
list: The images will be wrapped in <li>
array: The images will be returned as an array
plain: The images won’t be wrapped.

The $args do have to more options:
$args['before_the_image'] defines the HTML, which is shown before each image.
$args['after_the_image'] defines the HTML, which is shown after each image.

The gallery

ri_get_the_slider()
ri_the_slider()

Displays the gallery, which the plugin generates out of the product images. Optionally, you can provide a post ID or the current review will be used.