New here? Then you may want to subscribe to my rss feed. :)

Wordpress Blogroll bug fix

May 10th, 2007 | Posted in Development, Wordpress

I recently added a new feature to the home page. The “Sites and Articles of Interest” section is built using the Blogroll manager. As well as displaying the title and description, I wanted to display the date links were posted. Referring to Wordpress documentation I learnt that passing show_updated=true to wp_list_bookmarks() as an argument would return the date formatted, but it didn’t.

Digging into admin-db.php I discovered that when links are saved, the link updated date value had been left out. Therefore all links were defaulting to the database fields default value of 00-00-0000 00:00:00. The php template which holds wp_list_bookmarks() function checks the first two characters of the date, if they equal “00″ then it does not display the date.

To display the date I had to add the date field and value to the Blogroll’s save link SQL query, which is found in admin-db.php.

Backup admin-db.php, then at around line 350…ish, replace:

  1. if ( $update ) {
  2.                 $wpdb->query("UPDATE $wpdb->links SET link_url=’$link_url’,
  3.                         link_name=’$link_name’, link_image=’$link_image’,
  4.                         link_target=’$link_target’, link_category=’$link_category’,
  5.                         link_visible=’$link_visible’, link_description=’$link_description’,
  6.                         link_rating=’$link_rating’, link_rel=’$link_rel’,
  7.                         link_notes=’$link_notes’, link_rss = ‘$link_rss’
  8.                         WHERE link_id=’$link_id’");
  9.         } else {
  10.                 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(’$link_url’,'$link_name’, ‘$link_image’, ‘$link_target’, ‘$link_category’, ‘$link_description’, ‘$link_visible’, ‘$link_owner’, ‘$link_rating’, ‘$link_rel’, ‘$link_notes’, ‘$link_rss’)");
  11.                 $link_id = $wpdb->insert_id;
  12.         }

with

  1. $time = date(‘Y-m-d H:i:s’);
  2.         if ( $update ) {
  3.                 $wpdb->query("UPDATE $wpdb->links SET link_url=’$link_url’,
  4.                         link_name=’$link_name’, link_image=’$link_image’,
  5.                         link_target=’$link_target’,
  6.                         link_visible=’$link_visible’, link_description=’$link_description’,
  7.                         link_rating=’$link_rating’, link_rel=’$link_rel’,
  8.                         link_notes=’$link_notes’, link_rss = ‘$link_rss’,
  9.                         link_updated = ‘$time’
  10.                         WHERE link_id=’$link_id’");
  11.         } else {
  12.                 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss, link_updated) VALUES(’$link_url’,'$link_name’, ‘$link_image’, ‘$link_target’, ‘$link_description’, ‘$link_visible’, ‘$link_owner’, ‘$link_rating’, ‘$link_rel’, ‘$link_notes’, ‘$link_rss’,'$time’)");
  13.                 $link_id = $wpdb->insert_id;
  14.         }

Hope this helps others. Any problems then let me know.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>