You are here:  » Outputting lists of brands etc for use in widgets


Outputting lists of brands etc for use in widgets

Submitted by andydarley on Fri, 2011-09-16 23:00 in

How would I output the brands/categories/merchants in <ul> format?

If there's a line of PHP that will do it, I can put that into a PHP-enabled widget and use it across the site.

Also, how would I add a conditional call that used the merchant logo where one exists, instead of a text link?

Thanks in advance!

Submitted by support on Sat, 2011-09-17 09:32

Hi Andy,

I'm including Merchant, Category and Brand index widgets in the next release, which will be towards the end of next week! The PHP code is straight forward if you wanted to implement something in the mean time; assuming all global variables are declared as necessary; the brand index code would be along these lines;

    $sql = "SELECT DISTINCT(brand) AS brand FROM `".$pto_config_databaseTablePrefix."products` WHERE brand <> '' ORDER BY brand";
    if ($numRows = $wpdb->query($sql))
    {
      print "<ul>";
      for($i=0;$i<$numRows;$i++)
      {
        $row = $wpdb->last_result[$i];
        $href = $pto_config_permalink."?pto_q=brand:".urlencode($row["brand"]);
        print "<li><a href='".$href."'>".$row["brand"]."</a></li>";
      }
      print "</ul>";
    }

Cheers!
David.

Submitted by andydarley on Sat, 2011-09-17 11:37

I think I'd better wait for the new release - I got a blank output, presumably because of a lack of global variables. Which might also explain my last failed attempt at widgetry, when I wanted to add truncated descriptions to the features widget and just got an output %DESCRIPTION%, or some such thing.

I'm a CSS/HTML/design/copywriting person and PHP makes my head spin!

Oh - and thanks for posting the snippet... as ever, the support is appreciated.

Submitted by support on Sat, 2011-09-17 11:38

No worries, Andy - widgets involve class inheritance rather than being the most straight forward form of PHP but will all be included in next week's release!

Cheers,
David.