function amazonShortcode($atts, $content)
{
    // extract attributes
    extract(shortcode_atts(array('num' => ''), $atts));
    // We get $num variable
    if (empty($num)) {
        $num = 5;
    }
    // define HTML prefix and suffix for displayed App Store Box
    $preBox = '<hr style="border: 0; height: 0; border-top: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.3);">';
    $sufBox = '<hr style="border: 0; height: 0; border-top: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.3);">';
    // Require the class file
    // From https://github.com/chopin2256/Amazon
    require_once 'Amazon.php';
    //Run Amazon
    $amazon = new Amazon();
    //Instantiate Amazon object
    $kw = $content;
    //Set keyword
    $cnt = $num;
    //Set amazon max results, up to 10
    //Set config options
    $amazon->config()->API_KEY(get_option('amazon_shortc_apikey'))->SECRET_KEY(get_option('amazon_shortc_secretkey'))->associate_tag(get_option('amazon_shortc_associatetag'))->locale(get_option('amazon_shortc_locale'))->maxResults($cnt);
    //Search for keyword
    $amazon->search($kw);
    //Loop through array in for loop to save your Amazon results
    for ($i = 0; $i < $cnt; $i++) {
        $result .= amazonLayout($i, $amazon) . $sufBox;
    }
    //Clear amazon object
    $amazon->clear();
    //Set and return results, in this case, 5 product titles
    return $preBox . $result;
}
Esempio n. 2
0
function runAmazon()
{
    $amazon = new Amazon();
    //Instantiate Amazon object
    $kw = "product title";
    //Set keyword
    $cnt = 5;
    //Set amazon max results, up to 10
    //Set config options
    $amazon->config()->API_KEY('Your API')->SECRET_KEY('Your Secret Key')->associate_tag('associatetag-20')->locale('com')->maxResults($cnt);
    //Search for keyword
    $amazon->search($kw);
    //Loop through array in for loop to save your Amazon results
    for ($i = 0; $i < $cnt; $i++) {
        $result .= amazonLayout($i, $amazon);
    }
    //Clear amazon object
    $amazon->clear();
    //Set and return results, in this case, 5 product titles
    echo $result;
}