How Does AMM Work?
The Amazon Media Manager (AMM) allows you to display the data stored in your AMM database through the use of two things:
- A function called amm_getMedia
- A custom template
It allows you to insert the function amm_getMedia into your blog in two ways:
- By editing it directly into your wordpress templates
By adding a custom meta field to a page or post, then using a 'QuickTag' inside the post/page text that looks a little like this:
<!--amm_getMedia()-->
Don't worry, we'll be explaining how to do all of this in detail below.
The amm_getMedia() Function
This main function is what provides the flexibility to AMM. Those of you who have played around with Wordpress will know that to get your posts and stuff onto your blog, you use what are called "Hook Functions".
The getMedia function is just such a function, and it takes 5 parameters. All of these parameters are optional, as the function has a "Safe default" state.
The full function call looks like this:
amm_getMedia(template, items, group, sort, rating);
Usually you'll be calling the function from within a template and with some proper values, so you'll more than likely have something like this in your template:
<?php amm_getMedia('amm_default_output', 3, AMM_ALL); ?>
Calling the Function
We said this could be done in two ways, we weren't lying. The first method is to insert the function call into your template. Lots of people use it in their sidebar but because of the way WP1.5 lets you apply different templates all over the place, you can put amazon stuff anywhere you like! See the example:
<?php amm_getMedia('template', 3, AMM_ALL, AMM_DATE_DESC, AMM_RATING_ALL); ?>
The second way to do it, is to enter the function call as a quicktag into any page or any post, like so:
<!--amm_getMedia('template', 3, AMM_ALL, AMM_DATE_DESC, AMM_RATING_ALL)-->
Note When inserting the function as a quicktag, you don't need the & lt;?php tag, it's closing ?> tag and you don't need the semi-colon on the end either. If you have problems, refer back to this and make sure yours looks the same.
One final thing you must do to activate the 'Quicktag' in that post is to add a custom field to the post. To do this, when you're writing the post press the "Advanced Editing" button (It's next to publish) and then look down for a section called "Custom Fields"
Advanced editing button:
Custom Fields area:
Simply enter a new custom field with the following values:
key : amm
value : enabled
If you want to turn off the feature for the post you are editing, simply change the key value to disabled
Now, to explain those parameters... Skip to examples!
template
This should be set to the name of the template you wish to use to display the AMM data. There is no limit to the number of templates you can create, but you do have to create some! We'll get to that later.
This is a string, and must have single quotes around it.
items
This is an integer (Whole number) and does not need single quotes.
This controls how many items are displayed, so if you want to see 5 things, use the nubmer 5, that's it.
If you want to show as many items as AMM can find, pass 0 (zero).
groups
For this parameter you use a pre-defined 'Constant'. You type the constant in UPPERCASE, and you do not need to put single quotes around it.
This is where you decide which item types you would like to display. The default of (AMM_ALL) will display items from every category. We are using Amazon's "ProductGroup" to index things by, we didn't choose this, Amazon made us use it, so it's not ideal but it will do.
Here is a list of all available groups and what they will return:
- AMM_ALL -- All items (Default)
- AMM_APPAREL -- Apparel
- AMM_BOOKS -- Books
- AMM_BABY -- Baby, Baby Product
- AMM_BEAUTY -- Beauty, Health and Beauty
- AMM_ELEC -- CE (Consumer Electronics)
- AMM_GOURMET -- Gourmet, Restaurants
- AMM_TOOLS -- Home Improvement
- AMM_JEWELERY -- Jewelry
- AMM_KITCHEN -- Kitchen
- AMM_PATIO -- Lawn Patio
- AMM_INSTRUMENTS -- Musical Instruments
- AMM_OFFICE -- Office Product
- AMM_PC -- Personal Computer
- AMM_PHOTO -- Photography
- AMM_MISC -- Single Detail Misc Page
- AMM_SOFTWARE -- Software
- AMM_SPORTS -- Sports
- AMM_TOYS -- Toys
- AMM_WIRELESS -- Wireless
- AMM_PHONE -- Wireless Phone Accessory
- AMM_WATCH -- Watch
- AMM_GAMES -- Video Games
- AMM_MAGAZINE -- Magazine
- AMM_VIDEO -- Video
- AMM_DVD -- DVD
AMM_MUSIC -- Music
AMM_PRINT -- Books and Magazine
AMM_FILM -- Video and DVDs
AMM_CLOTHING -- Apparel and Jewelry and Watch
AMM_ELECTRICAL -- CE and Personal Computer and Photography and Wireless and Wireless Phone Accessory
AMM_SW -- Software and Video Games
AMM_HOME -- Home Improvement and Kitchen and Lawn Patio
AMM_ENTERTAINMENT -- Books and and Video Games and Magazine and Video and DVD and Music
These are all defined in the amm_constants.php file. Examine this file and you should be able to make your own groups by copying how groups like AMM_HOME and AMM_SW were made.
If you want to pass a selection of items too the getMedia function, pass them through as shown below, using the 'pipe' to separate the terms, eg:
AMM_WATCH|AMM_BOOKS|AMM_PHOTO
The above example would display Watches, Books and Photographic equipment.
sort
For this parameter you use a pre-defined 'Constant'. You type the constant in UPPERCASE, and you do not need to put single quotes around it.
This parameter lets you decide how the returned items are sorted.
Default: AMM_DATE_DESC
5 values are available:
- AMM_DATE_ASC -- Date Ascending
- AMM_DATE_DESC -- Date Descending
- AMM_RATING_ASC -- Rating Ascending
- AMM_RATING_DESC -- Rating Descending
- AMM_RANDOM -- Random!
The default will display the most recent items first.
rating
$Rating
For this parameter you use a pre-defined 'Constant'. You type the constant in UPPERCASE, and you do not need to put single quotes around it.
This parameter lets you filter the results based on the ratings you have given the items you store.
Default: AMM_RATE_ALL (Display all ratings)
This lets you filter your results based on the ratings they have. There are several possible values, explained below:
- AMM_RATING_ALL - Default, shows items of any rating
- AMM_RATING_5 - Shows items with a rating of 5
- AMM_RATING_4
- AMM_RATING_3
- AMM_RATING_2
- AMM_RATING_1
AMM_RATING_0 - Shows items with a rating of 0
AMM_RATING_4UP - Shows items with a rating 4 or above
- AMM_RATING_3UP
- AMM_RATING_2UP
AMM_RATING_1UP - Shows items with a rating of 1 or above
AMM_RATING_1DOWN - Shows items with a rating of 1 and below
- AMM_RATING_2DOWN
- AMM_RATING_3DOWN
- AMM_RATING_4DOWN - Shows items with a rating of 4 and below
Using these it should be possible to filter your outputs in as many combinations as you please.
Example Functions
Below are some examples of how to call amm_getMedia. Use these to learn from so you find it easier to write your own:
Get 3 of your latest books:
amm_getMedia('amm_default_output',3,AMM_BOOKS,AMM_DATE_DESC,AMM_RATING_ALL);
Get 1 random movie, which you rated more than 3:
amm_getMedia('amm_default_output',1,AMM_DVD,AMM_RANDOM,AMM_RATING_3UP);
Get all watches and clothes, sort by rating with the highest first:
amm_getMedia('amm_default_output',0,AMM_WATCH|AMM_APPAREL,AMM_RATING_DESC);
Remember, if you want to leave a parameter out, you must leave the commas in!
3 items, any rating, with default sort and category:
amm_getMedia('amm_default_output',3,,,AMM_RATING_ALL);
The getMediaID() function
This function is used when you want to get a specific, single item out from the database. You must first know it's ID, get this by looking in the AMM Management page and remembering the ID you want to display.
Next, call the function just like you'd call the standard amm_getMedia(), but this time you need only two parameters, like so:
<?php amm_getMediaID('template_name',45);?>
OR for quick-tag use:
<!--amm_getMediaID('template_name',45)-->
Obviously, change 'template_name' to the template you want to use and change the 45 to the id of the item you want to display.
Creating AMM Templates
Please refer to Creating Templates for instructions!