Wordpress How to Show blogroll form specific link category
Wp links hack: how to show links from specific link category only
Well, Wordpress provide lot of plugins for show blogroll in widget and other places even link pages too, But some time we need to find out solution to display links on any page or footer,
suppose we have many link categories and want to show only specific category links on any page how we can do that ?
Here is the solution
By this codes you just need to use “slug” of link category and link will display.
global $wpdb; $query = "SELECT link_url, link_name, link_description, link_rating FROM $wpdb->links, wp_term_relationships WHERE link_id = object_id AND link_visible = 'Y' AND term_taxonomy_id = ( SELECT wp_term_taxonomy.term_taxonomy_id FROM wp_term_taxonomy WHERE term_id = (SELECT DISTINCT term_id FROM wp_terms, wp_term_relationships WHERE slug = 'link-cat' AND taxonomy = 'link_category')) ORDER BY rand() LIMIT 3";
e.g: link-cat = you can add your link category slug here.
How to Display by link Category id
global $wpdb; $query = "SELECT link_url, link_name, link_description, link_rating FROM $wpdb->links, wp_term_relationships WHERE link_id = object_id AND link_visible = 'Y' AND term_taxonomy_id = ( SELECT wp_term_taxonomy.term_taxonomy_id FROM wp_term_taxonomy WHERE term_id = 'you-catid') ORDER BY rand() LIMIT 3";
e.g: you-catid = you can add your link category id here
now next to display links
after use above any one codes you can use this code below to display links
$results = $wpdb->get_results($query); echo "<ul>"; foreach ($results as $result) { $link_name = $result->link_name; $link_description = $result->link_description; echo '<li><a href="'.$link_url.'" rel="external" target="_blank" title="'.$link_name.'">'.$link_name.'</a><br>'.$link_description.'</li>'; } echo "</ul>";
enjoy ![]()













January 24th, 2012 at 11:47 am
Great article! I admire your work very much!