Revision: 21788
Updated Code
at December 21, 2009 06:34 by ReeceMarsland
Updated Code
function sitehelper_get_membernav(){ //get current url to build relative links $base = trim($_GET['q']); //url matching to prevent multiple arguments for first letter e.g "membership-list/key/a/b" if(strstr($base, 'membership-list/key')){ $base = 'membership-list/key'; }elseif (strstr($base, 'membership-list/sponsor')){ $base = 'membership-list/sponsor'; }elseif (strstr($base, 'membership-list/regular')){ $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"; $term = substr($base, 16); 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 $items = array(); 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>'; foreach(range('A','Z') as $i) { if($items[$i] == 1) { $output .= ' | <a href="/'.$base.'/'.strtolower($i).'">'.strtoupper($i).'</a>'; } else { $output .= ' | <span>'.strtoupper($i).'</span>'; } } return $output; }
Revision: 21787
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 21, 2009 06:13 by ReeceMarsland
Initial Code
function sitehelper_get_membernav(){ //Select distinct first letters of current nodes $result = db_query("SELECT DISTINCT substring( node.title, 1, 1 ) AS letter FROM {node}, {content_type_member} WHERE node.type = 'member' AND node.status = '1' AND content_type_member.nid = node.nid ORDER BY node.title ASC"); //array to hold our first letters $items = array(); while ($row = db_fetch_array($result)) { $items[$row['letter']] = 1; } //get current url to build relative links $base = trim($_GET['q']); //url matching to prevent multiple arguments for first letter e.g "membership-list/key/a/b" if(strstr($base, 'membership-list/key')){ $base = 'membership-list/key'; }elseif (strstr($base, 'membership-list/sponsor')){ $base = 'membership-list/sponsor'; }elseif (strstr($base, 'membership-list/regular')){ $base = 'membership-list/regular'; }else { $base = 'membership-list/all'; } //Build output for A-Z matching all first letters from $items when possible $output = '<a href="/'.$base.'/all">All</a>'; foreach(range('A','Z') as $i) { if($items[$i] == 1) { $output .= ' | <a href="/'.$base.'/'.strtolower($i).'">'.strtoupper($i).'</a>'; } else { $output .= ' | <span>'.strtoupper($i).'</span>'; } } return $output; }
Initial URL
Initial Description
Initial Title
Alphabet Pagination
Initial Tags
php, drupal
Initial Language
PHP