WPG2 and new theme

After failing to find a theme for my blog I liked well enough, I finally took the plunge and designed this one, as much as possible from scratch. There’s stuff in from the default theme, as well as good colours from all over the place. I may eventually release it when I’m sure that it’s actually complete, and that weird bugs are mostly ironed out.

The plus side is that the WPG2 plugin I couldn’t get to work on my previous theme now works perfectly, which is good news as I can stop using the kludged together iframe tag gallery page I used before.

The only problem I encountered was using the wp_list_bookmarks() function so that I could use WordPress’s built in link manager. The default list outputs the description seemingly as an afterthought, which is very annoying when you would like to style it. Using get_bookmarks() is more flexible but doesn’t allow you to pull out the categories.

By digging into the core files I found out how the WordPress team did it, and wrote my own (much simpler) bit of code, put it in as a template and produced my own links section with a styleable link description:

Place this in a template, I called mine links
	<ul class="link-list">
 
	< ?php
 
		// This line gets all of the link categories
		$cats = get_terms('link_category', array('name__like' => '', 'include' => '', 'exclude' => '', 'orderby' => 'name', 'order' => 'ASC', 'hierarchical' => 0));
 
		// loop through the categories
		foreach($cats as $cat)
		{
 
			// Put the categories into a list
			echo "<li id='linkcat-".$cat->term_id."' class='linkcat'>";
 
			echo "<h2>".$cat->name."</h2>";
 
			// Get the bookmarks that are a part of the current category in the loop
			$bookmarks = get_bookmarks(array('category'=>$cat->term_id));
 
			echo "<ul>";
 
			// Loop through each of the bookmarks that are part of the category
			foreach($bookmarks as $bookmark)
			{
 
				echo "<li>";
 
				echo "<a href='".$bookmark->link_url."' >".$bookmark->link_name."</a>";
 
				// if the link description exists, output this
				if($bookmark->link_description)
				{
					echo " &raquo; ";
 
					echo "<div class='link-description'>".$bookmark->link_description."</div>";
 
				}
 
				// If an image exists as part of the link, output that.
				// The image is linked to the URL of the link it is a part of
				if($bookmark->link_image)
				{
 
					echo "<div>";
					echo "<a href='".$bookmark->link_url."' >";
					echo "<img src='".$bookmark-/>link_image."' alt='Image for ".$bookmark->link_name."' />";
					echo "</a>";
					echo "</div>";
 
				}
 
				echo "</li>";
 
			}
 
			echo "</ul>";
 
			echo "</li>";
 
		}
	?>
 
	</ul>

Leave a Reply

You must be logged in to post a comment.