Create a simple “shop” page in Textpattern
This tutorial assumes that you have a fairly strong understanding of HTML and CSS, as well as a basic understanding of Textpattern and its tags. (I won’t be going into detail about the css) We will be building a very simple “shop” type page in Textpattern. There are plugins which allow Textpattern to integrate paypal support, but this is a fairly simple alternative. This allows you to feature products which you may sell through paypal, e-junkie, Amazon (or whatever else you may be using) The structure of this page is built with the client in mind – they don’t need to format the page with any html or div’s in order to get the products laid out nicely.
Two example links of this simple functionality in action are:
1. http://www.meghantelpner.com/shop/?c=books
2. http://www.elmwoodspa.com/shop/
In the first example, you can click on one of Meghan’s books to see more information before deciding to purchase. If you click on “buy now”, you will be taken to her e-junkie store. Additionally, if you click on a specific book to see more information, you get a small navigation block at the top of the article that allows you to quickly browse the next and previous products. You may notice that if you click on one of the other submenus within her store, such as the Books/DVDs/Audio, that you will be taken directly to the Amazon affiliate link for that product. The client has the capacity to choose whether or not to link the product to an external link (Amazon, e-junkie, paypal) or whether or not to link to the full product page itself first, with a “buy now” button.
In the second example, you can click to see details/shop online which takes you immediately to Elmwood Spa’s online store.
I will be using the first example as a basis for the tutorial.
Plugins used: cbs_category_list, zem_nth (both optional) and upm_image
First you’ll want to set up some custom fields, depending on how you want your shop to function. For Meghan’s shop, there are instances where she links to external products via a buy now button. Other times, she’ll want to link to an external site without the buy now button. So I have created 2 custom fields, “link to this site” and “buynow.” If you link exclusively to Paypal links, you could name it paypal, or whatever is easy for you to remember. (As long as you adjust it accordingly in the article forms)

Now let’s take a look at one of the product pages inside textpattern:

1. The title that will appear on the shop landing page
2. The description that will appear only one the item is clicked on
3. This is the link that the thumbnail and title will link to if you put a link (full url) here, otherwise:
4. A buy now button will appear and will link to the full url pasted here (if a link is not placed in either field, the title and thumbnail will merely link to the full article page automatically)
5. Place the image id number here that you want to associate with the article (the thumbnail version of this image will appear on the shop landing page, while the full image size will show on the individual article page.)
6. Choose the appropriate section for your article, in this instance, “shop.”
7. Select the appropriate categoryfor the article (if applicable. You may not have a need for categories)
8. IF USING THE BUY NOW FIELD you must use the override form named shop_listing2 (I’ll explain below)
SAVE your article!

shop subnav
In the actual page template for the shop, the code that calls the shop submenu (books and guides, etc) looks like this:
<txp:cbs_category_list parent="shop" wraptag="ul" break="li" class="subnav" section="shop" showcount="false" class="subnav" activeclass="active"/>
Using the plugin cbs_category_list, this pulls a list of all of the categories with a parent category of “shop”, wraps each category in a list tag, wraps the whole thing in an unordered list with a class of subnav, and assigns a class of active on list items when they are active. Handy dandy! You don’t necessarily need to use this plugin if your shop does not need this type of subnav.
Ok, so how do we pull all of our shop items into the page? The article tag in our shop page template looks like this:
<txp:article listform="shop_listing" form="shop" limit="99" sort="posted asc"/>
So this tag basically says: on the landing page (or listform version of the page), display the articles using the form of “shop_listing”. If you’re looking at an individual article page, (i.e. an individual product page) display the article using the form “shop”. Limit the amount of articles shown to 99, and sort them by date of Posted Ascending.
The “shop_listing” form looks like this:
<div class="shop-item"> <a href="<txp:permlink />"><txp:upm_article_image type="thumbnail" class="shopimg"/></a> <h3><txp:permlink><txp:title /></txp:permlink></h3> <span><a href="<txp:custom_field name="buynow" />">BUY NOW</a></span> </div>
Translation: the thumbnail version of the article’s image is being pulled from the “Article image” field in the article, and assigned the class of “shopimg” for styling purposes. Both the title and thumbnail are linked to the permanent link to the article (which will show the body/description of the product. The Buy Now button links to whatever gets put into the custom field named “buynow.” The shop-item css looks something like: .shop-item {float:left; margin:20px 25px 10px 0; width:175px; }
Alternately, if you want to get really nerdy, you could use the plugin zem_nth to tell every third (or whatever number) post to display with different class. I use it to apply “shop-item-last” (which has a margin-right of zero) to every third item , so the last item in every row doesn’t have any extra margin space on the right. You can choose to do your layouts with or without zem_nth. This is what my shop_listing article form really looks like:
<txp:zem_nth step="1" of="3"><div class="shop-item"></txp:zem_nth><txp:zem_nth step="2" of="3" ><div class="shop-item"></txp:zem_nth><txp:zem_nth step="3" of="3" ><div class="shop-item-last"></txp:zem_nth><a href="<txp:permlink />"><txp:upm_article_image type="thumbnail" class="shopimg"/></a><h3><txp:permlink><txp:title /></txp:permlink></h3><span class="register"><a href="<txp:custom_field name="buynow" />">BUY NOW</a></span></div><txp:zem_nth step="3" of="3" ><hr class="space" /></txp:zem_nth>
The “shop_listing2″ form (for products without a buy now button, linking externally) looks like this:
<div class="shop-item"> <a href="<txp:custom_field name="link to this site" />" rel="external"><txp:upm_article_image type="thumbnail" class="shopimg"/></a> <h3><a href="<txp:custom_field name="link to this site" />"><txp:title /></a></h3> </div>
This tells the title and thumbnail on the listing page to link directly (in a new window/tab) to the link that is found in the “link to this site” field shown in the image above, #3. You could also include the <txp:excerpt /> tag if you wanted to include an excerpt. If you want the article to appear this way (without the buy now button), you need to ensure that you are using the override_form in the article named “shop_listing2″.
Now that we have set up what the listing page looks like for product pages, let’s look at how the individual product pages look. If you will recall the article form we used:
<txp:article listform="shop_listing" form="shop" limit="99" sort="posted asc"/>
We need to create a form called “shop” that will determine how the individual pages look once you click on the thumbnail/title.
The “shop” article form looks like this:
<p><a href="/shop">Back to Shop</a> | <txp:link_to_prev>Previous Product</txp:link_to_prev> | <txp:link_to_next>Next Product</txp:link_to_next></p> <div class="right"><txp:upm_article_image/><br /><span class="register" ><a href='<txp:custom_field name="buynow"/>' >BUY NOW</a></span></div><txp:body />
Translation: The tags inside the paragraphs set up a small subnav which allows the user to click through to the next/previous products. Then it puts the full version of the article image in a div labelled “right” (which I float right in my css), below that place a Buy Now button which links to the url provided in the “buynow” custom field. Then display the body of the article. You could of course format the tags however you want. (image on top with text below, etc). Individual product page pictured below:

individual product page
Using custom fields is a great way to allow the client (who doesn’t know how to code) to be able to add new items to the shop easily without having to see any textpattern or html tags, and avoid them forgetting to close link tags and add things like rel=”external”. Yay!
This tutorial assumes that you have textpattern installed and ready to go, and have a good grasp of the tags.
( Download the latest version of Textpattern here: http://textpattern.com/download )
Did I miss anything? If you need any more clarity or have any questions, please feel free to put them in the comments, and I will do my best to help.
Happy Coding!
Marie Poulin is a freelance graphic designer specializing in interactive design & strategy. She builds clean, usable websites using Textpattern, HTML and CSS. Twitter


Lovely! Will give this tutorial a go later on this month….
This is great, I need to implement this type of thing for my site. I need to display all the categories and articles headers for these categories down the side (Tree).
You then click on a parent category and display a list view of each product on the page, and then click through to display the article product itself
Im pretty new to textpattern and love the tutorials you give.. they are very clear and help.
Thanks, Rob!
I too also found working with categories very convoluted at first. Perhaps I should focus on categories for an upcoming tutorial…
It would be great if you could find some time to implement this in an up and coming tutorial.
Thanks for your comment..
Hey Rob,
shoot me an email, give me some more details, and I’ll work it into a tutorial!
:D
Marie,
Thanks so much for doing this e-commerce tutorial for textpattern. I have been doing sites using txp for a few years now. I absolutely love it. Lots for me to learn yet. I implemented e-commerce on a txp site which is working fine but ecstatically unpleasing to the eye. This may help me make the site more intuitive and transparent to the client, thereby always keeping them on the site through to the sale point. I attempted yab_shop but ended up using an outside cart source and placing that into forms to implement for now. I also live in the Vancouver area(Langley). I would like to get in touch with you. Would this be fine?