Results 1 to 4 of 4
  1. #1
    Full Member jazzylee77's Avatar
    Join Date
    February 19th, 2005
    Posts
    199
    Display Random Item
    Anyone know a way to display a random item from a shop?

    I'm working on a php solution using the rss feed from a shop.

    Credit due...Totally borrowed code from blackhatdigest.com/tutorials/random-rss-item-with-php-and-iconv-for-formatting/


    PHP Code:
    <?
    function load_xml_feed($location)
    {
    global 
    $value1;
    $feedXml simplexml_load_file($location);

    $i'1';
    foreach (
    $feedXml->channel->item as $article)
    {
    $title[$i] = (string)$article->title;
    $link[$i] = (string)$article->link;
    $description[$i] = (string)$article->description;

    $i++;

    }
    $randnumber rand(2$i);
    $link trim($link[$randnumber]);
    $title trim($title[$randnumber]);
    $description trim($description[$randnumber]);
    $title iconv("UTF-8""ISO-8859-1"$title);
    $description iconv("UTF-8""ISO-8859-1"$description);
    $value1 = array($title,$link,$description);
    return 
    $value1;
    }

    $rss 'http://shops.popshops.com/shops/get-this-url-from-pop-it-in-rss.rss';
    load_xml_feed($rss);
    $link $value1[1];
    $title $value1[0];
    $description $value1[2];

    echo 
    $link;
    echo 
    $title;
    echo 
    $description
    ?>
    I put this in a .php file with a real popshops rss feed link and succeed in getting random items from that shop.

    Problem is... the description begins with a long ugly popshops url like this

    Code:
    http://r.popshops.com/r/LzlaS3QyME11NnFsRksybHZBaEFMS1M3NHFlQWtLZ09XMGo1US80Zk1lVT0K
    Par for the course... I tend to figure things out as I post. Pretty obvious really, just remove the echo $link; Line.

    But now i want to fancy it up...make the link work in title, add some <h3> tags etc...

    echo "<h3><a href='$link'>$title</a></h3>";

    PHP Code:
    <?
    function load_xml_feed($location)
    {
    global 
    $value1;
    $feedXml simplexml_load_file($location);

    $i'1';
    foreach (
    $feedXml->channel->item as $article)
    {
    $title[$i] = (string)$article->title;
    $link[$i] = (string)$article->link;
    $description[$i] = (string)$article->description;

    $i++;

    }
    $randnumber rand(2$i);
    $link trim($link[$randnumber]);
    $title trim($title[$randnumber]);
    $description trim($description[$randnumber]);
    $title iconv("UTF-8""ISO-8859-1"$title);
    $description iconv("UTF-8""ISO-8859-1"$description);
    $value1 = array($title,$link,$description);
    return 
    $value1;
    }

    $rss 'http://shops.popshops.com/shops/get-this-url-from-pop-it-in-rss.rss';
    load_xml_feed($rss);
    $link $value1[1];
    $title $value1[0];
    $description $value1[2];
    echo 
    "<h3><a href='$link'>$title</a></h3>";
    echo 
    $description
    ?>
    Thanks for paying attention and making me work it out myself.

    Then again there may be a more elegant way...
    Last edited by Bill; August 30th, 2010 at 08:30 PM. Reason: Unlinked

  2. #2
    Full Member jazzylee77's Avatar
    Join Date
    February 19th, 2005
    Posts
    199
    ack, the above solution did me little good in the end. Wanted to run it through yahoo pipes and into something else, but pipes "page fetch" isn't what I had hoped. Messed with parsing it in html, then making it pretty xml... no go with the picky page fetch at pipes.

    Need to either find a way to create a random item feed output or figure how to pull a random item from the feed with yahoo pipes.

    If I could find a decent php execute plugin that worked with WordPress 3.0 i could throw my php snippet in a page and do a single page feed by tagging ?feed=rss2&withoutcomments=1 to the url.

    (I've tried several php plugins in the past few hours with no luck)

    There may be a script that would create an rss feed from a php page.

    Sleepy... try again tomorrow...

  3. #3
    ABW Ambassador 2busy's Avatar
    Join Date
    January 17th, 2005
    Location
    Tropical Mountaintop
    Posts
    5,636
    Have you tried just setting your PopShops to Autofeed? Not sure if that would always be random or just give you the first products in the feed though.

  4. #4
    Full Member jazzylee77's Avatar
    Join Date
    February 19th, 2005
    Posts
    199
    Quote Originally Posted by 2busy View Post
    Have you tried just setting your PopShops to Autofeed? Not sure if that would always be random or just give you the first products in the feed though.
    The rss feed is an ordered list of the items in the order they occur in the shop. no pagination, not affected by autofeed.

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. [LS] Diamonds International - Buy 1 Item Get 2nd Item 40% off Sale!
    By Jon Nunez in forum AffiliateManager.com
    Replies: 1
    Last Post: December 28th, 2007, 06:28 PM
  2. Possible to display random single products?
    By Radegast in forum Cusimano.com Scripts
    Replies: 9
    Last Post: December 12th, 2006, 04:59 AM
  3. More item Shipped than Ordered Item!!
    By eWESTPost in forum Amazon
    Replies: 6
    Last Post: January 24th, 2006, 03:40 PM
  4. Ordered item and shipped item
    By shilmy in forum Amazon
    Replies: 9
    Last Post: September 26th, 2005, 09:26 AM
  5. Random HTML
    By drumminlogan in forum Programming / Datafeeds / Tools
    Replies: 4
    Last Post: December 23rd, 2002, 07:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •