Custom bookmarks list by category
-
I’m using get_bookmarks instead of wp_list_bookmarks because I need to be able to display the notes field, and I have it working but can’t figure out how to segment the list by categories. I could hard-code in a category name or ID, but I’d rather structure this so that if in the future more links categories are added the list will automatically update with the new category and sub-list of bookmarks.
This is what I’m using that works but doesn’t segment by category:
$bookmarks = get_bookmarks( array( 'orderby' => 'name', 'order' => 'ASC', )); foreach ( $bookmarks as $bookmark ) { printf( '<li><a href="%s">%s</a>',$bookmark->link_url, $bookmark->link_name ); if(!($bookmark->link_notes == "")) { printf( '<br /><span class="linksnotes">'); printf( $bookmark->link_notes ); } printf( '<span></li>' ); }
I have also a Custom Post Type that prints posts by the CPT custom category, so I tried modifying that to work with link categories, but it doesn’t work – it prints the category name, followed by the entire list of links, followed by the next category name and again the entire list of links….
$tax = 'link_category'; $tax_terms = get_terms($tax); if ($tax_terms) { foreach ($tax_terms as $tax_term) { echo '<h2>'. $tax_term->name .'</h2>'; $bookmarks = get_bookmarks($args); $args = array( 'category_name' => $tax_term->name, 'orderby' => 'name', 'order' => 'ASC', ); foreach ( $bookmarks as $bookmark ) { printf( '<li><a href="%s">%s</a>',$bookmark->link_url, $bookmark->link_name ); if(!($bookmark->link_notes == "")) { printf( '<br /><span class="linksnotes">'); printf( $bookmark->link_notes ); } printf( '<span></li>' ); } } }
Can anyone help me figure out what I’m doing wrong?
- The topic ‘Custom bookmarks list by category’ is closed to new replies.