Eric Nagel

Eric Nagel

CTO, PHP Programmer, Affiliate Marketer & IT Consultant

An Affiliate Website Anyone Can Build

I have been, or can be if you click on a link and make a purchase, compensated via a cash payment, gift, or something else of value for writing this post. Regardless, I only recommend products or services I use personally and believe will be good for my readers. screenshotI know a lot of my posts are rather technical, but this one is a bit different. I’m going to show you an affiliate website that anyone can build, and walk you through exactly how I did it.

First, you need a niche. I’ve covered this before, How to Choose an Affiliate Offer to Promote. For this site, it was all about a love (some may say obsession) I have with Christmas and the movie, A Christmas Story.

I met with A Christmas Story House at the recent ShareASale ThinkTank, which boosted this project to the top of my list. (Hear that, merchants? When you meet with affiliates face-to-face, you become a priority to them). What resulted from this meeting is Buy Leg Lamps. screenshot
Buy Leg Lamps

Here’s how the site was created, in about 20 hours

  1. Buy the domain name. Don’t spend too long here. I like domains that start with “buy” and then add the product name.
  2. Install WordPress, add theme. For this site, I went with eStore by Elegant Themes. For $39 you get access to all their themes. eStore looked like a shopping site, which is what I wanted to do.
  3. Start adding products, manually. Yep… this merchant doesn’t have a datafeed, so I was manually adding products. As I looked over their products, I came up with my own categories on my whiteboard, then I started populating them. It took a while to figure out the image sizes that the theme wanted, but once I knew, I was able to go through the products pretty quick. I have 55 products on the site, from A Christmas Story House and
  4. Add something more than just products. In this case, I added a YouTube video of the trailer from A Christmas Story

Now I’d be lying if I said I didn’t do any custom programming on the site. There are a few things I wanted to change.

As an affiliate, my goal is to get the cookie set. So, I changed the links to go to through the affiliate link, and not the shopping cart links. You’ll notice my links look like: /addtocart.php?nProductID=218. I wanted the user to think they were buying the product at this site! addtocart.php is simple:

	define('WP_USE_THEMES', true);

	$cQuery = "select * from wp_postmeta where meta_key='afflink' and post_id=" . (int)$_GET['nProductID'] . " limit 1";
	$oResult = mysql_query($cQuery);
	if ($rsData = mysql_fetch_array($oResult)) {
		header("Location:  " . $rsData['meta_value']);
	} // ends
	else {
		header("Location:  /");
	} // ends else from

I add a custom field to each post called afflink and that’s the affiliate link.

I also added Facebook’s commenting, so when a user comments on a product, the comment is shared on their Facebook page, and shown to their friends. If you’re using eStore, edit /wp-content/themes/eStore/includes/single-product.php and add

<div id="fb-root"></div><script src=""></script><fb:comments href="<?= $_SERVER['REDIRECT_URL'] ?>" num_posts="6" width="615"></fb:comments>

Then, do a little SEO on the site:

Finally, showoff your site to other Elegant Themes users in their customization showcase and then start getting your backlinks! (BTW, if you liked this post, I’d appreciate a backlink to my Leg Lamp site)

  • Shawn Collins
    Posted June 9, 2011 11:23 am 0Likes

    Two important questions – do you have a leg lamp and why no Facebook commenting on this blog?

    • Eric Nagel
      Posted June 9, 2011 11:30 am 0Likes

      Of course I have a Leg Lamp! It’s only on display during Christmas time, though (Black Friday ’til New Years Eve)

      I’m happy with the commenting in Thesis. I also don’t want to lose my current comments. For new sites, I consider Disqus, Facebook, as they have easy plug-ins.

      • Shawn Collins
        Posted June 9, 2011 11:34 am 0Likes

        I’ve been considering Facebook comments – it would stink to lose current comments, but I figure most posts don’t get comments after a week or so anyway.

  • Logan Thompson
    Posted June 9, 2011 11:54 am 0Likes

    Great post Eric. Just to play devils advocate, what value does this site have to the end user just out of curiosity? Nice looking site.

    • Eric Nagel
      Posted June 9, 2011 12:08 pm 0Likes

      Well, I am pulling in just Leg Lamps, and Leg Lamp products. And reorganizing them.

      Sometimes it’s not about adding value… it’s about getting the cookie set πŸ™‚

    • Eric Nagel
      Posted June 9, 2011 1:05 pm 0Likes

      Oh, I thought of another value…

      There are 10 results in the SERPs. Would you, as a merchant, want to be #1 (merchant site), or #1 (merchant site) and #2 (merchant-specific affiliate)?


  • Amit
    Posted June 9, 2011 12:53 pm 0Likes

    Nice post.
    Without a datafeed how do you plan to keep the site current. Won’t you have to manually replace/modify products/pricing/availability info.

    Plus the ‘Add to Cart’ button to give the impression that the user is buying from your site can be misleading, from my own experience. Buyers thought they bought from my affiliate site and wd shoot customer service emails/complaints to me. Now I clearly mention ‘Buy from’ to avoid the confusion.

    • Eric Nagel
      Posted June 9, 2011 1:07 pm 0Likes

      Yeah, when I go to update the site, I’ll probably build a tool to quickly update the prices.

      As for the “Add to Cart” button, I want the user to click & get the cookie set. That’s my goal, as an affiliate. If I say “Buy from”, the user could just type into their browser “” and I don’t get credit for the sale.

  • noodles
    Posted June 9, 2011 1:49 pm 0Likes

    looks like a great approach. I may redo some of my sites with a similar template. How long has the leg site been up and what kind of traffic / sales are you getting?

  • imagine
    Posted June 9, 2011 3:15 pm 0Likes

    Its awesome when you can sell something that you love with regards to the movie. My brother and I have been watching A Christmas Story every Christmas since before I can remember and a few years ago we met with some of the cast members in downtown Cleveland (im originally from the Cleveland area) and also visited the house where they took the exterior shots of it in the movie.

    Thanks for sharing about your site!

  • Brian Jones
    Posted June 9, 2011 5:40 pm 0Likes

    I will be sure to get you that datafeed. So things will run smoothly with little site maintenance on your end.

  • Chris Guthrie
    Posted June 10, 2011 2:28 am 0Likes

    Hey Eric,

    It’s so cool that you wrote this post because I actually have an epically awesome podcast interview coming up with that guy who bought the A Christmas Story house and he talks about how he slowly built his business from his apartment and how he found the house on eBay and decided to buy it to try and build up his business etc. etc.

    Don’t mean to go all self promotional on you lol but I absolutely love A Christmas Story and Christmas Vaction so I tracked the guy down to interview him. I’ll let you know when it’s up and as always great post dude. I love the actionable tips.

    • Eric Nagel
      Posted June 10, 2011 7:50 am 0Likes

      Hey Chris – yeah, that’d be Brian (commented above). I was star-struck when I met him (he probably didn’t know that). Having visited the house myself, it was great meeting him.

      Can’t wait to hear your podcast!

  • Gerald
    Posted June 15, 2011 4:50 am 0Likes

    Hey Eric, i saw earlier that you add a custom field called “afflink”.
    Well, i installed a plugin called “Affiliate Link Cookie Maker” and i think it does what you are describing above, and maybe you are using this plugin? Thing is i just can’t get it to work, i’m not tech savvy but it sounds like the same thing you are talking about, but i still can’t get it right. Was wondering if you could explain the it a bit more in the most simplistic way possible πŸ™‚

    • Eric Nagel
      Posted June 15, 2011 6:46 am 0Likes

      Hi Gerald,

      No, I’m not using that plugin. What I did was create a new file, addtocart.php (code above) which pulls the value of “afflink” from the postID that’s passed to it.

      Try creating a post with an afflink value, then use the addtocart.php script I’ve given.

      The preg_match line is just because I was lazy, and didn’t want to keep generating deeplinks, so this takes care of it for me.

  • Josh
    Posted June 30, 2011 1:26 am 0Likes

    Any other modifications that need to be changed before creating the addtocart.php? I’ve been trying to get my eStore theme to work like yours by using an affiliate link instead of the cart, but nothing is working. Can you post any other modifications and edits to the theme?


    • Eric Nagel
      Posted June 30, 2011 8:10 am 0Likes

      Hey Josh –

      The theme needs to be changed to link to addtocart

      If you email me your site, I’ll take a look at it

  • Bayar
    Posted July 8, 2011 3:16 am 0Likes

    Sexy leg lamp. It’s funny.

  • Hugo
    Posted July 14, 2011 10:58 am 0Likes

    Thanks a bunch for sharing that piece of code, awesome!

    By the way; your affiliate website looks so much more appealing than the actual site from the merchant (oops!) They should do a redesign, I bet they can increase conversions on their end quite a bit.

  • Trisha Lyn Fawver
    Posted October 18, 2011 3:06 pm 0Likes

    One of these days I’m going to attempt this…

  • Bolts
    Posted December 8, 2011 1:48 pm 0Likes

    Nice site! Do you have any Scut Farkus t-shirts? Why not expand the catalog to all things Christmas Story?

    • Eric Nagel
      Posted December 8, 2011 4:13 pm 0Likes

      I was thinking about that, but really wanted to focus on the Leg Lamp. I’ve added a few other things this year, and may expand again next season.

  • Elwood
    Posted January 25, 2012 4:56 pm 0Likes

    Nice walk through!

    I have a question regarding one of my sites that I have using the elegant theme e-store. I have a feed setup from amazon to update the reviews and prices. It updates in its on custom field called amzn_LowestNewPrice, do you know how I have that copy into the e-store price custom field?

    • Eric Nagel
      Posted January 25, 2012 7:07 pm 0Likes

      Personally, I’d write a cron that updates the estore custom field with the amzn_LowestNewPrice value. Or have it done each time the product page is called. Or update the eStore template to use amzn_LowestNewPrice. You have a few choices – what you choose depends on how often the prices change, and how much traffic the site gets.

      • Elwood
        Posted January 25, 2012 9:13 pm 0Likes

        Hi Eric,

        Thanks so much for your reply.
        The changes wont be very frequent, maybe every couple of weeks if that. The custom cron function seems like a good idea but I think this may be beyond by level of expertise πŸ™‚


  • Adam
    Posted February 1, 2012 8:49 pm 0Likes

    Would it be possible to get some help setting up the php code you have on my site? I’m not exactly sure where to enter my shareasale affiliate code and product ID. I’d greatly appreciate it if you could help me out.



  • Trackback: 3 Articles Worthy of Affiliate Marketer’s Attention « Affiliate Marketing Blog by Geno Prussakov
  • Austin
    Posted April 5, 2012 9:56 pm 0Likes

    This is awesome. I have been pretty disapointed with the various Amazon affiliate store fronts that I’ve tried and found your site in the Elegant Themes forum. It’s nice to have such a different looking theme as an affiliate store vs. all of the same same type sites out there using the same store builder scripts and themes.

    Quick question for you… how are sales going? Are you converting a lot of buyers? I have been an Amazon affiliate for quite some time now and the majority of my success is when referring people through text links. I get very few cookies set from people clicking “add to cart” and conversion rates on actual sales are terrible compared to test links.

    If you’d be willing to share how things are going that’d be great.

    Thanks for posting exactly how to turn the theme into an affiliate theme. It’s awesome!

    Take care,


    • Eric Nagel
      Posted April 6, 2012 8:35 am 0Likes

      Hi Austin –

      Sales were great around Christmas, as expected, but have slowed down. Honestly, I’ve ignored the site, but have it on my calendar to get back on it Sept-1.

      • Austin
        Posted April 6, 2012 9:24 pm 0Likes

        Thanks for the reply. I’m going to give it a shot for the next product I choose to promote.


  • Sean
    Posted June 6, 2012 5:51 pm 0Likes

    Hi Eric,

    I’m wondering whether you would recommend the WordPress Amazon-Associate Plug-in with your E-Store site.

    Also, are their plug-ins that automate the coding that you wrote above?

    I am a newbie to all of this, so even your coding above is intimidating. πŸ™‚



    • Eric Nagel
      Posted June 7, 2012 4:49 am 0Likes

      Hi Sean,

      Sorry, but I’ve never used an Amazon Associates Plugin.

      Don’t be afraid to try this out… it’s the only way to learn new things.

  • Sean
    Posted June 8, 2012 3:15 am 0Likes

    Thank you, Eric! I took your advise to heart and am delving into your code – the first I’ve ever worked with.

    – Fortunately, I was able to figure out how to add the Facebook commenting code to my single-product.php code. It looks great and I really appreciate that lead.
    – I love how some of your Add To Cart buttons are linked directly to the Amazon product page. Did you add the addtocart.php to the single-product.php code? Also, I’m not sure how I would replace your and other personalized data with my Amazon data.
    – Can you share the ‘afflink’ field code that you added to each post? Did you just post that in the product description field?

    If this is too much to ask, then I understand. All of your information above has given me hope that personalizing my dream site is within my scope of ability… with sweat and tears. I really appreciate your generous sharing already. – Sean

    • Eric Nagel
      Posted June 8, 2012 6:48 am 0Likes

      OK – I simplified my addtocart.php code above. The other thing you need to do is add a custom field to your WordPress posts.

      When you’re editing a post, in the upper-right there’s a button called “Screen Options” – click that, and make sure “Custom Fields” is enabled. Now, scroll down and find the Custom Fields box. The name of your new custom field should be afflink and the value should be your affiliate link

  • Sean
    Posted June 8, 2012 11:19 pm 0Likes

    Thank you! I now have the afflink fields in my posts.

    I tried inserting the addtocart.php code it into many points of the single-product.php template, but to no avail. Which template does the addtocart.php code fit into? And which part of the template?

    I’ll definitely be referring people to you as a paid consultant for their projects now. Thanks again. πŸ™‚

    • Eric Nagel
      Posted June 9, 2012 7:16 am 0Likes

      Sorry this wasn’t clearer… addtocart.php is a NEW FILE that you have to create. Just copy the code above, paste into a new file, then upload to your server.

      Then you edit single-product.php to point to addtocart.php:

      <a href="/addtocart.php?nProductID=<?= $post->ID ?>" class="addto-cart"><span><?php _e('Add to cart','eStore'); ?></span></a>
  • Sean
    Posted June 10, 2012 12:44 am 0Likes

    You’ve helped me come a long way, Eric! I’m so close I can taste it. πŸ™‚

    – I created the addtocart.php file using the exact code that you posted above and uploaded it using cPanel (in Web Hosting Hub) to the public_html “wp-includes” folder.

    – I copied your new code (from above) and pasted it over the following code in the single-product.php file:

    – I entered an Amazon’s Associates product page link into the afflink field into my post.

    – The result? The content of the post is replaced with the following: Parse error: syntax error, unexpected ‘=’, expecting ‘,’ or ‘;’ in home/dharma12/public_html/wp-content/themes/eStore/includes/single-product.php on line 48

    – I played around with the single-product.php addtocart code that you supplied this morning, which seemed to help, but I could never bring back the nice green Add To Cart button. I kept accidentally replacing the green button with a written link ($post-rel=”nofollow”>ID ?>” class=”addto-cart”>Add to cart), but that link sent me to an error page stating the following: The requested URL /addtocart.php?nProductID= was not found on this server.

    I love how your leglamp website works; I’m just trying to figure out how to make the Add To Cart button so clean as yours. Any suggestions would be MUCH appreciated! πŸ™‚
    Your protege,

    • Mark Gubarenko
      Posted December 14, 2012 7:45 am 0Likes

      i have the same error as you, with “unexpected”, how did you work through??

  • Sean
    Posted June 11, 2012 5:32 pm 0Likes

    Hi again, I just figured it out! Thanks for all of your help, Eric. MUCH appreciated! – Sean

  • Eric Nagel
    Posted June 12, 2012 8:55 am 0Likes

    Nice job! If you need anything else, feel free to ask

  • Matt
    Posted August 1, 2012 4:20 pm 0Likes

    Your code is pulling the proper post ID but when add to cart is clicked I always get “nothing found for Addtocart.php?nProductID=1” (for example)

    meta afflink is being used. Check out the code on for great justice.

    Cheers in advance!

    • Eric Nagel
      Posted August 1, 2012 4:25 pm 0Likes

      Make sure you copy the code for addtocart.php and upload this file to the root of your site (

  • Crystal
    Posted September 3, 2012 5:14 pm 0Likes

    Thank you! My website has been getting traffic, and I was looking for a way to use estore as my affiliate store instead of just a blog trying to look like one. You’ve laid it out nicely! Thank you sooooooooooooooooo much!

  • Sean
    Posted October 31, 2012 11:08 pm 0Likes

    Thanks again for all of your help, Eric. I appreciate the inspiration and help that you provided me with my Amazon affiliate site.

  • Earl
    Posted December 3, 2012 8:25 am 0Likes

    Hi Erik! Thanks for the Tips. I got a problem when I edit the single-page.php using the follow code

    <a href="/addtocart.php?nProductID=ID ?>” class=”addto-cart”>

    After publishing the post it becomes a blank content page. Please help. Thank you.

    • Eric Nagel
      Posted December 7, 2012 10:25 am 0Likes

      If you see a blank page, you’re getting an error somewhere. Turn on your error display, or look at your server PHP error log.

  • Earl
    Posted December 3, 2012 8:26 am 0Likes

    Sorry I meant this code

    <a href="/addtocart.php?nProductID=ID ?>” class=”addto-cart”>

  • mimi
    Posted December 13, 2012 11:49 pm 0Likes

    That’s really cool, thanks for the info you have shared!
    I also am in the process of using the estore theme and was wondering how you managed to change the sidebar (where you put ebay listings and the video)?
    I’m a beginner and would love to change mine too πŸ˜‰

    • Eric Nagel
      Posted December 14, 2012 1:11 pm 0Likes

      you can control what’s in the sidebar via widgets: /wp-admin/widgets.php

  • Mark Gubarenko
    Posted December 14, 2012 6:38 am 0Likes

    I’ve tried to do everything as written, i’ve added addtocart.php to root folder, added afflink as custom field, but when i try open product it shows this

    Parse error: syntax error, unexpected ‘=’, expecting ‘,’ or ‘;’ in /home/content/14/8196014/html/analogplanet/wp-content/themes/eStore/includes/single-product.php on line 48

    Can you look at
    there’s just one product as we speak.

    • Eric Nagel
      Posted December 14, 2012 1:10 pm 0Likes

      Mark – your line 48 will be different than mine, due to some changes I’ve made. Email it to me and I’ll take a look for you.

  • Josef Reisz
    Posted December 18, 2012 6:45 pm 0Likes

    Just stumbled over this great tutorial! I’ll be testing this setup with a website I’ve run for about a year now. Not knowing exactly how to monetize it. Now I know. πŸ˜‰ THX

  • george
    Posted March 16, 2013 2:45 am 0Likes

    Hello there Eric, nice Job!
    Could you tell me how to link the images with aff links when working with datafeed?

    • Eric Nagel
      Posted March 18, 2013 8:29 am 0Likes

      Hi George,

      In this particular case, I’m just linking the image to /addtocart.php?nProductID=13. Add this to eStore/includes/single-product.php

      <a href="/addtocart.php?nProductID=<?= $post- rel="nofollow">ID ?>">

      <img itemprop="image" src="<?php echo($custom["thumbs"][$i]); ?>" alt="<?php the_title(); ?>" />

      It may be slightly different, as I’ve altered my theme a bit since the original download.

  • Josef Reisz
    Posted March 25, 2013 7:29 pm 0Likes

    Alright, testing this on this website:

    However, I can’t get the “Add to Cart” Button work with the afflink. It returns an empty page.

    I created the addtocart.php and put it in the root. Then I made the changes in the single.php file.

    What am I missing?

    • Eric Nagel
      Posted March 26, 2013 9:05 am 0Likes

      An empty page means PHP errors are being suppressed. Either log your errors, or display them, to see what’s going on. echo(), print_r(), and exit() are your debugging friends

  • David Neff
    Posted March 24, 2015 1:13 pm 0Likes

    I attended last year’s Share A Sale event as an affiliate and I totally agree with you about meeting face to face with merchant’s. I have several ideas for niche sites to promote products from some of the vendors that took the time to explain their merchant programs and showed an interest in what I do. They are at the top of my list.
    Out of curiosity, is the Leg Lamp site making any commissions at this point?

    • Eric Nagel
      Posted March 24, 2015 1:18 pm 0Likes

      Hi David,

      Yep! Still making commissions on Leg Lamps, every month! Each year I tell myself I’m going to freshen up the site in Q3, but never get around to it, but it’s doing well

      • David Neff
        Posted March 24, 2015 2:22 pm 0Likes

        Awesome to hear you are making commissions on the site πŸ™‚ Almost seemed to niche to me, but the more I think about, everybody needs a leg lamp!

        Here’s ours….

        P.S. Nice choice with Elegant Themes. I use their themes on my sites too.

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.