Home » Resources » Documentation » Design and Layout » Shortcodes and Template Tags

Shortcodes and Template Tags

So what is the difference between a shortcode and a template tag? The main difference is that a shortcode is a snipped of text you place directly into a WordPress post or page, while a template tag gets put in the actual template file. Whether you use one or the other depends solely on how much you want to customize your theme. From a visual standpoint, a shortcode is looks like this

[dosomething]

While a template tag looks like this

<?php do_something(); ?>

Here are some examples of when you might want to use the WP e-Commerce shortcodes.

I want to display all of my products on a page (or post) other than my Products Page
If you want to display a list of products from your default category on a specific page (or post), you would edit the page, and add [​productspage​] wherever you want them to appear.

I want to only display products from a specific category on a page (or post) other than my Products Page
First you want to find out the shortcode for the specific category. You can do this by going to your Store > Categories page and clicking the edit button beside your desired category. To the right, you will see all the attributes for that group, as well as a “Display Category Shortcode” which shows you the shortcode you will need. Copy that shortcode and paste it into whatever page or post you want the products to appear on.

I want to display a particular product on a particular page (or post)
First you want to find the shortcode for the particular product. You can do this by going to Products > Products and clicking the edit button next to your desired product. If you click on the information icon (the little blue circle with the letter “I”) you will see every possible shortcode and PHP tag related to that product. You can also add a “Buy Now” or “Add to Cart” button to your new product location by copying the shortcodes for them. Keep in mind, an “Add to Cart” or “Buy Now” button cannot exist on its own without an associated product, so make sure you copy the product shortcode first!

I want to display a list of my product categories somewhere besides the sidebar
If you want to display a list of your product categories (including thumbnail images) at a particular location on a specific page, you would edit the page, and add

wherever you want them to appear.

Note the shortcode:

[ wpsc_products category_url_name='ruby' number_per_page='2' ]

will not use pagination if you have pagination turned off in settings>Presentation page

How can I do something differently depending on the category?
You can check $wpsc_query->category, e.g.

if ($wpsc_query->category == 1) {
// Do something
}

How can I do something differently depending on the product being viewed?
You can check $wpsc_query->product_id, e.g.

if(wpsc_the_product_id() == 10){
// Do something
}else {
// Do something else
}

Template Tags

Many of the shortcodes listed above have corresponding template tags, though for the most part it’s easier to use the shortcodes. However, here are a list of available template tags should you need them.

Display Shopping Cart:< ?php echo nzshpcrt_shopping_basket(); ?>
List Categories: < ?php show_cats_brands(); ?>
Buy Now: < ?php echo wpsc_buy_now_button(1); ?>
Add to Cart: < ?php echo wpsc_add_to_cart_button(1); ?>
Display Latest Products: <?php nzshpcrt_latest_product(); ?>
Display SKU: <?php echo wpsc_product_sku(wpsc_the_product_id());  ?>