Custom display of Links

I didn’t like the way my links came out with wplistbookmarks or any other built-in function, so I needed a way to have total control about the way my WordPress bookmarks were displayed. In this example I wanted a table with the Bookmark-image in the left column and title and description in the right column.

This should probably go into a separate page template but should basically work anywhere in your theme.

Code Snippet:

<?php
//get links from database (works outside of loop)
$links = $wpdb->get_results("SELECT * FROM $wpdb->links ORDER BY link_name ASC");

  //start the table
  echo "<table border='0' class='linktable'>";
    //start going through all the links and get the required values for each link
    foreach ($links as $link) {
      $linkurl=$link->link_url;
      $linkdesc=$link->link_description;
      $linkname=$link->link_name;
      $linkimage=$link->link_image;
      $linknotes=$link->link_notes;

      //write a table row for each link with the link image in the left cell and name and description in right cell
      echo "<tr><td><a href='$linkurl' target='_blank'><img src='$linkimage' alt='$linkurl' border='0' class='linkimg'></a></td>";
      echo "<td valign='top' class='link-desc'><h5>$linkname</h5>";
      echo "<div class='link-description'>$linkdesc </div></td></tr>";
    }
//finish going through all the links
echo "</table>";
//close the table
?>

Posted in Pure hacks