S2 Cookbook: Modules
From Dreamwidth Notes
Revision as of 00:11, 20 December 2012 by Foxfirefey (Talk | contribs)
To override the order or content of the navigation module, override this function with the following (note the comments, some options should be removed or changed for unpaid accounts or communities).
# code by ninetydegrees function print_module_navlinks() { var Page p = get_page(); var string[] navlinks_order = []; var string{} navlinks_urls = {}; var string{} navlinks_text = {}; $navlinks_order = [ "recent", "archive", "read", # remove this for unpaid journals "network", "tags", "memories", # remove these if you don't want to add custom links "custom1", "custom2", "userinfo", ]; $navlinks_urls = { "recent" => "$p.base_url/", "archive" => "$p.base_url/archive", "read" => "$p.base_url/read", "network" => "$p.base_url/network", "tags" => "$p.base_url/tag", "memories" => "$*SITEROOT/tools/memories?user=$p.journal.username", "custom1" => "http://URL", "custom2" => "http://URL", "userinfo" => "$p.base_url/profile", }; $navlinks_text = { "recent" => "$*text_view_recent", "archive" => "$*text_view_archive", # use $*text_view_friends_comm for communities "read" => "$*text_view_friends", "network" => "$*text_view_network", "tags" => "$*text_view_tags", "memories" => "$*text_view_memories", "custom1" => "Custom Text", "custom2" => "Custom Text", "userinfo" => "$*text_view_userinfo", }; open_module("navlinks", "", ""); var string[] links = []; foreach var string k ($navlinks_order) { if ($navlinks_urls{$k} != "") { var string css = """ class="$k" """; if ($p.view == $k) { $css = """ class="current $k" """; } $links[size $links] = """<a href="$navlinks_urls{$k}"$css>$navlinks_text{$k}</a>"""; } } print_module_list($links); close_module(); }
The following navlinks override checks to see if the page is an entry/day/recent/month page; if it is, it adds previous and next links to the beginning and end of the list of links.
function print_module_navlinks( bool apply_class_to_link ) { var Page p = get_page(); var string prev_link; var string next_link; if ( $p isa EntryPage ) { var EntryPage ep = get_page() as EntryPage; var Entry e = $ep.entry; var Link prev = $e->get_link("nav_prev"); $prev_link = """<a href="$prev.url">$prev.caption</a>"""; var Link next = $e->get_link("nav_next"); $next_link = """<a href="$next.url">$next.caption</a>"""; } elseif ( $p isa DayPage ) { var DayPage dp = get_page() as DayPage; $prev_link = """<a href="$dp.prev_url">$*text_day_prev</a>"""; $next_link = """<a href="$dp.next_url">$*text_day_next</a>"""; } elseif ( $p isa RecentPage ) { var RecentPage rp = get_page() as RecentPage; if ( $rp.nav.backward_count > 0 ) { $prev_link = """<a href="$rp.nav.backward_url">""" + get_plural_phrase( $rp.nav.backward_count, "text_skiplinks_back" ) + "</a>"; } if ( $rp.nav.forward_count > 0 ) { $next_link = """<a href="$rp.nav.forward_url">""" + get_plural_phrase( $rp.nav.forward_count, "text_skiplinks_forward" ) + "</a>"; } } elseif ( $p isa MonthPage ) { var MonthPage mp = get_page() as MonthPage; if ($mp.prev_url != "") { $prev_link = "<a href='$mp.prev_url'>Previous</a>"; } if ($mp.next_url != "") { $next_link = "<a href='$mp.next_url'>Next</a>"; } } open_module("navlinks", "", ""); if ( $apply_class_to_link ) { var string[] links = []; if ( $prev_link ) { $links[size $links] = $prev_link; } foreach var string k ($p.views_order) { var string css = """ class="$k" """; if ($p.view == $k) { $css = """ class="current $k" """; } $links[size $links] = """<a href="$p.view_url{$k}"$css>"""+lang_viewname($k)+"""</a>"""; } if ( $next_link ) { $links[size $links] = $next_link; } print_module_list($links); } else { var string{}[] links = []; if ( $prev_link ) { $links[size $links] = { "class" => "previous", "item" => $prev_link }; } foreach var string k ($p.views_order) { var string class = $k; if ($p.view == $k) { $class = "current $k"; } $links[size $links] = { "class" => $class, "item" => """<a href="$p.view_url{$k}">"""+lang_viewname($k)+"""</a>""" }; } if ( $next_link ) { $links[size $links] = { "class" => "next", "item" => $next_link }; } print_module_list($links); } close_module(); }