Sample code to pull ebay affiliate auctions and display them in wordpress

Discussion in 'PHP' started by darkmessiah, Feb 18, 2008.

  1. #1
    Here is some (older) sample code to get you up and running quickly. I have moved on to a class based system at this point, and I don't mind share this code. I want to show people it's easier than you think.

    I have not tested this exact code, as I have chopped out a bunch of stuff that didn't need to be in here.

    ##########Main part put this code in a .php file#############
    <?php 
    
    $ebayxml = array();
    $yourpid = "1234567";
    $tomorrow = date("Ymd")+5;
    $today = date("ymd");
    
    
    function makerss($keywords){
    	global $ebayxml,$yourpid,$tomorrow,$today;
    
    
    	$xmlsrc="http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&language=en-US&output=RSS20&sacqy=&catref=C5&dfte=1&sacur=0&dfs=".$today."&sorefinesearch=1&fsop=32&fsoo=2&from=R14&saobfmts=exsif&dff=1&dfe=".$tomorrow."&_trksid=m37&sacqyop=ge&saslc=0&floc=1&sabfmts=0&saprclo=&saprchi=&saaff=afcj&fcl=3&frpp=50&afcj=".$yourpid."&nojspr=yZQy&satitle=".$keywords."&afmp=&sacat=-1&saslop=1&fss=0&dfts=24";
    
    	$ch = curl_init(); 
    	curl_setopt($ch, CURLOPT_URL, $xmlsrc); 
    	curl_setopt($ch, CURLOPT_HEADER, FALSE); 
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    	$data = curl_exec($ch); 
    	curl_close($ch);
    
    	$xml = simplexml_load_string($data);
    	$xml = $xml->children();
    	$cnt = 0;
    
    
        	foreach ($xml->children() as $item) {
     		if(($item->getName()=="item")&&$cnt<20){
    			$ebayxml[$cnt] = array();
    			$xmlLink = $item->link;
    			$xmlTitle = $item->title;
    			$xmlDescription = $item->description;
    			$ebayxml[$cnt]['link']=$xmlLink;
    			$ebayxml[$cnt]['title']=$xmlTitle;
    			$ebayxml[$cnt]['desc']=$xmlDescription;
     			$cnt++;
    		}
        	}
    	$ebayxml['count']=$cnt;
    }
    
    function outputebay($itemnum){
    	global $ebayxml;
    
    	$xmlLink = $ebayxml[$itemnum]['link'];
    	$xmlTitle = $ebayxml[$itemnum]['title'];
    	$xmlDescription = $ebayxml[$itemnum]['desc'];
    
    	echo "<br><a href='{$xmlLink}' target='_blank' name='{$xmlTitle}'>{$xmlTitle}</a><br>{$xmlDescription}<br>";	
    }
    
    ?>
    Code (markup):
    ###########This code calls the function based on wordpress tags####

    Put this code in the single.php file in Wordpress.
    
    $kw = get_the_tags();
    	if($kw<>""){
    		foreach($kw as $k){
    		 $words.=$k->name."+";
    		}
    		$words = substr($words,0,strlen($words)-1);
    		include("yourfilename.php");ebayrss($words);
    	}
    
    Code (markup):
    Put it in after..
    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    Code (markup):
    And before..
    <p class="postmetadata alt">
    Code (markup):

    Now whenever you make a post, just put in some tags and this will take care of the rest.

    I am still working on my main project still, life has me doing other things right now.

    Like I said I didnt test this yet. Just run the makerss function with a keyword that is formated like, "kw+kw+kw" then run outputebay(auctionnumber).
     
    darkmessiah, Feb 18, 2008 IP
  2. hwould

    hwould Peon

    Messages:
    374
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm curious, has anyone tried this?
     
    hwould, Apr 17, 2008 IP