You are here:  » Shortcode Questions


Shortcode Questions

Submitted by newpbc on Wed, 2011-09-14 14:23 in

Hi I've a few questions about shortcodes first can they be called from the template files. Secondly how much work would it be to set up a custom shortcode based on the product shortcode.
What I’m trying to do is on wp single post pages display the full output from the product shortcode then on wp category pages show just the image and best price and possibly a snippet of the description.

Submitted by support on Wed, 2011-09-14 15:24

Hi,

I'll investigate the use of shortcodes on template files - I'm not sure WordPress is actually in the mode where shortcodes are processed at the point where template files are included.

Regarding a shortcode to replicate an entire product page (for your manually created product pages), simply use each attribute in sequence, for example

[pto product="Red Widget" prices="Red Widget"]

(you could also add related="Red Widget" if you wanted to display related products also but that may not be appropriate for your standalone product pages.

Category pages are generated by the search results HTML. The default search result output sounds close to what you want, but if you want to reduce the snippet length you'll find the constant value 200 (to the nearest whole word after) on line 366 of pto_search.php

Hope this helps!
Cheers,
David.

Submitted by Fuzzy on Tue, 2012-04-24 00:25

Just done this myself and would like to share this:

If you want to display a Wordpress shortcode outside the loop, eg: in a template file, simply add the code like this:

<?php
 
echo do_shortcode('[pto]'); 
?>

Submitted by support on Tue, 2012-04-24 08:28

Thanks, Fuzzy!

Cheers,
David.
--
PriceTapestry.com