wp_list_bookmarks not enough?!
-
Hi there,
I’ve been really tinkering with the list bookmarks function in the last while. I was delighted to work out that I could add enough code through sensible use of
title_after
andafter
to get my description wrapped in a span for the purposes of styling.However on a new site I’m working on as well my friend wants to have a highly structured list page.
The structure was intended as follows:
<h3>category_name<h3> <ul> <li><img src="link_image" /> <h4>link_name(not linking though)</h4> <p>Description</p> <p><a href="link_url">link_title</a></p> </li> </ul>
and so on ad infinitum.
In my investigation of things I could see no way that wp_list_bookmarks could do this for me.
The biggest problem was that
show_images=1
resulted in the link_name being replaced by the image and this then acted as the link. This would not fit into the overall style of the site.In addition there was no way to display the link_url separately as a link and not have the link_name as the link.
So.. I went on a bit of a quest and came up with a solution. I’m not the best php/MySQL coder in the world and the resulting code feels messy to me. I was wondering could anyone have a look at this and tell me if I’m going a very long way around and whether this way of coding things results in excessive database calls or anything?
<?php $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => '', 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1, 'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '<h2>', 'title_after' => '</h2>', 'category_orderby' => 'name', 'category_order' => 'ASC', 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">', 'category_after' => '</li>'); extract($defaults); $cats = get_categories("type=link&category_name=$category_name&include=$category&orderby=$category_orderby&order=$category_order&hierarchical=0"); // Begin foreach loop 1 displaying the categories foreach ( (array) $cats as $cat ) { $params = array_merge($defaults, array('category'=>$cat->cat_ID)); $bookmarks = get_bookmarks($params); if ( empty($bookmarks) ) continue; $catname = apply_filters( "link_category", $cat->cat_name ); $cat_ID = apply_filters( "link_category", $cat->cat_ID ); echo '<h3>' . $catname . '</h3>'; // Work out which links are in each listed category!! $link_IDs = $wpdb->get_results("SELECT link_id FROM $wpdb->link2cat WHERE category_id=$cat_ID"); foreach ($link_IDs as $link_ID) { $ID = substr($link_ID->link_id,0,1000); // This worked, but I'm not sure why. I turned the id into a string instead of an array? $last = "$ID"; $loop .= " OR link_id=$last"; } $links = $wpdb->get_results("SELECT * FROM $wpdb->links WHERE link_id=$last$loop ORDER BY link_name"); echo '<ul>'; foreach ($links as $link) { echo '<li>'; $img_name = substr($link->link_image,0,4); // If there is an image this will set img name as "http" if (($img_name)==("http")) {echo '<p><img src="' . $link->link_image . '" alt="' . $link->link_name . ' website" /></p>';} // If there is an image, display it echo '<h4>' . $link->link_name . '</h4>'; echo '<p>' . $link->link_description . '</p>'; echo '<p class="clear">Visit this site: <a href="' . $link->link_url . '">' . $link->link_url . '</a></p></li>'; } // end of link listing loop echo '</ul>'; // Return the link id variables to null $last=null; $loop=null; // return to start of category loop. If no more cateogries continue } // end category loop ?>
I hope this makes sense. It was the only way I could come up with a solution and I’m sure there is a more graceful way. Anyone have any thoughts?
- The topic ‘wp_list_bookmarks not enough?!’ is closed to new replies.