Title: Randomize on Refresh via PHP Sidebar Widget?
Last modified: September 1, 2016

---

# Randomize on Refresh via PHP Sidebar Widget?

 *  Resolved [expatgirl](https://wordpress.org/support/users/expatgirl/)
 * (@expatgirl)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/randomize-on-refresh-via-php-sidebar-widget/)
 * I’m trying to throw together a randomize-on-refresh sidebar widget of Amazon 
   Product in a Post. I’ve already created a static PHP widget of AmPP, which shows
   one item (which is all I wish to show at any given time).
 * I’ve found a PHP function that works within a PHP-enabled text widget for producing
   randomization of strings, which – again – I have limited to one displayed result.
 *     ```
       <?php
       $input = array
       ("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
       $rand_keys = array_rand($input, 1);
       echo $input[$rand_keys] . "\n";
       ?>
       ```
   
 * PHP is not my strong point, so here’s the question…
 * How can I successfully pass the AmPP shortcode into the array – or vice versa–
   so that it displays one randomized AmPP post at a time?
 * My first thought is setting up the full “amazonproducts ASIN=****” shortcodes
   into the array. (Although, for the life of me, I can’t figure out the syntax 
   for making that display correctly, given the brackets around the shortcode.)
 * My second thought is setting up an array within the shortcode itself, with the
   individual ASINs passed in as randomized array values, and using echo do_shortcode
   to display the output. (Part of me thinks this would be cleaner than the first
   option.)
 * My third thought is… ask for help.
 * In conjunction with all that (and potentially nullifying my second thought), 
   I found this: [Don’t do_shortcode()](https://codesymphony.co/dont-do_shortcode/).
 * Ideas? Guidance? Cribbable code with explanation of why it works?
 * Anybody? Bueller? Bueller? Bueller…
 * [https://wordpress.org/plugins/amazon-product-in-a-post-plugin/](https://wordpress.org/plugins/amazon-product-in-a-post-plugin/)

The topic ‘Randomize on Refresh via PHP Sidebar Widget?’ is closed to new replies.

 * ![](https://ps.w.org/amazon-product-in-a-post-plugin/assets/icon.svg?rev=1565235)
 * [Amazon Product in a Post Plugin](https://wordpress.org/plugins/amazon-product-in-a-post-plugin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amazon-product-in-a-post-plugin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amazon-product-in-a-post-plugin/)
 * [Active Topics](https://wordpress.org/support/plugin/amazon-product-in-a-post-plugin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amazon-product-in-a-post-plugin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amazon-product-in-a-post-plugin/reviews/)

## Tags

 * [amazon](https://wordpress.org/support/topic-tag/amazon/)
 * [marketing](https://wordpress.org/support/topic-tag/marketing/)
 * [monetizing](https://wordpress.org/support/topic-tag/monetizing/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [products](https://wordpress.org/support/topic-tag/products/)
 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 0 replies
 * 1 participant
 * Last reply from: [expatgirl](https://wordpress.org/support/users/expatgirl/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/randomize-on-refresh-via-php-sidebar-widget/)
 * Status: resolved