function ubik_links_sidebar($sidebar) { if (is_page_template(UBIK_LINKS_PAGE_TEMPLATE)) { // Retrieve the list of all categories $cats = ubik_links_categories(); // Add the links page template to the bottom of the list (relies on `get_permalink`) $cats[] = '<strong><a class="link-category" href="' . get_permalink() . '">' . __('All links', 'ubik') . '</a></strong>'; $cats = ubik_links_categories_list($cats); // Output the links sidebar $sidebar = '<aside id="ubik-links-search-widget" class="widget widget-links-search"><h2>' . __('Search links', 'ubik') . '</h2>' . ubik_links_search_form() . '</aside>'; // A list of link categories if (!empty($cats)) { $sidebar .= '<aside id="ubik-links-categories-widget" class="widget widget-links-categories"><h2>' . __('Link categories', 'ubik') . '</h2>' . $cats . '</aside>'; } } return $sidebar; }
function ubik_links_categories_list($id_or_array = '') { // Initialize $list = ''; // Allow this function to accept a link ID or an array of link categories already generated by `ubik_links_categories` if (is_array($id_or_array)) { $cats = $id_or_array; } else { $cats = ubik_links_categories($id_or_array); } // Make sure we have something... if (!empty($cats)) { // Loop through each link category and assemble the list foreach ($cats as $cat) { $list .= '<li>' . $cat . '</li>'; } $list = '<ul class="link-categories">' . $list . '</ul>'; } return $list; }