/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function sitehelper_get_membernav(){ //get current url to build relative links //url matching to prevent multiple arguments for first letter e.g "membership-list/key/a/b" $base = 'membership-list/key'; $base = 'membership-list/sponsor'; $base = 'membership-list/regular'; }else { $base = 'membership-list/all'; } $terms = ''; $where = ''; //join terms table if url has a taxonomy argument if($base != 'membership-list/all'){ $terms = "LEFT JOIN {term_node} term_node ON node.vid = term_node.vid". " INNER JOIN {term_data} term_data ON term_node.tid = term_data.tid"; print $term; $where = "AND term_data.name = '".$term."'"; } //Select distinct first letters of current nodes $result = db_query("SELECT DISTINCT substring( node.title, 1, 1 ) AS letter FROM {node} node LEFT JOIN {content_type_member} content_type_member ON content_type_member.nid = node.nid ".$terms." WHERE node.type = 'member' AND node.status = '1' AND content_type_member.nid = node.nid ".$where." ORDER BY node.title ASC"); //array to hold our first letters while ($row = db_fetch_array($result)) { $items[$row['letter']] = 1; } //Build output for A-Z matching all first letters from $items when possible $output = '<a href="/'.$base.'/all">All</a>'; if($items[$i] == 1) { } else { } } return $output; }