How to create sidebar widget in wordpress websites

Sample code to create sidebar widget in wordpress websites
Following is an example to create and register sidebar widget in wordpress based websites,
<?php /* Plugin Name: isedn-Partner Widget Description: isedn featured listing Version: 0.1 Author: http://forum.indiacitys.com */ function isedn_partner_widget() { $countcat = 0; $catinit = get_the_category(); $countcat = count($catinit); if ($countcat <= 0) { $srcexactseek = 'free'; echo '<p align="center" style="background-color:blue;"><font size="4" color="white"><b><u>Featured listings</u></b></font></p>'; $exactseekxml = "http://xml.exactseek.com/cgi-bin/fl-xmlsearch.cgi?id=XXXXX&term=".$srcexactseek; $string = file_get_contents($exactseekxml); $xml = new SimpleXMLElement($string); $countxml = 0; $countxml = $xml->searchinfo->paidhitcount; // $countxml = count($xml); if ($countxml > 0) { foreach($xml->paidresults->paidlisting as $product) { $wordpress_post_title = $product->title; $wordpress_post_redirect = $product->redirect; $wordpress_post_displayurl = $product->displayurl; $wordpress_post_content = $product->description; echo "<hr><b> <a href='".$wordpress_post_redirect."' target='_blank' > ".$wordpress_post_title."</a></b><br>"; echo $wordpress_post_content; } } } if ($countcat > 0) { foreach((get_the_category()) as $category) { $postcat= $category->cat_ID; $catname =$category->cat_name; } $srcexactseek = $catname; $exactseekxml = "http://xml.exactseek.com/cgi-bin/fl-xmlsearch.cgi?id=XXXXX&term=".$srcexactseek; echo '<p align="center" style="background-color:blue;"><font size="4" color="white"><b><u>Featured listings</u></b></font></p>'; $string = file_get_contents($exactseekxml); $xml = new SimpleXMLElement($string); $countxml = 0; $countxml = $xml->searchinfo->paidhitcount; if ($countxml == 0) { $srcexactseek = 'free'; $exactseekxml = "http://xml.exactseek.com/cgi-bin/fl-xmlsearch.cgi?id=XXXXX&term=".$srcexactseek; $string = file_get_contents($exactseekxml); $xml = new SimpleXMLElement($string); $countxml = 0; $countxml = $xml->searchinfo->paidhitcount; } // $countxml = count($xml); if ($countxml > 0) { foreach($xml->paidresults->paidlisting as $product) { $wordpress_post_title = $product->title; $wordpress_post_redirect = $product->redirect; $wordpress_post_displayurl = $product->displayurl; $wordpress_post_content = $product->description; echo "<hr><b> <a href='".$wordpress_post_redirect."' target='_blank' > ".$wordpress_post_title."</a></b><br>"; echo $wordpress_post_content; } } } } function isedn_partner_init() { register_sidebar_widget(__('ISEDN WIDGET'), 'isedn_partner_widget'); } add_action('widgets_init', 'isedn_partner_init'); ?>
Sign In or Register to comment.