Difference between revisions of "S2 Cookbook: Modules"

From Dreamwidth Notes
Jump to: navigation, search
Line 70: Line 70:
  
 
== Add previous/next links to navigation links on entry pages ==
 
== Add previous/next links to navigation links on entry pages ==
 +
 +
The following navlinks override checks to see if the page is an entry page; if it is, it adds previous/next entry links to the beginning/end of the list of links.
  
 
<syntaxhighlight lang="s2">function print_module_navlinks( bool apply_class_to_link ) {
 
<syntaxhighlight lang="s2">function print_module_navlinks( bool apply_class_to_link ) {

Revision as of 06:47, 19 December 2012

Navigation

Change the order or content of the navigation links

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();
}

Add previous/next links to navigation links on entry pages

The following navlinks override checks to see if the page is an entry page; if it is, it adds previous/next entry links to the beginning/end of the list of links.

function print_module_navlinks( bool apply_class_to_link ) {
    var Page p = get_page();
    var Entry e;
 
    if ( $p.view == "entry" ) {
        var EntryPage ep = get_page() as EntryPage;
        $e = $ep.entry;
    }
 
    open_module("navlinks", "", "");
 
    if ( $apply_class_to_link ) {
        var string[] links = [];
 
        if ( $p.view == "entry" ) {
            var Link prev = $e->get_link("nav_prev");
            $links[size $links] = """<a href="$prev.url">$prev.caption</a>""";
        }
 
        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 ( $p.view == "entry" ) {
            var Link next = $e->get_link("nav_next");
            $links[size $links] = """<a href="$next.url">$next.caption</a>""";
        }
 
        print_module_list($links);
    } else {
        var string{}[] links = [];
 
        if ( $p.view == "entry" ) {
            var Link prev = $e->get_link("nav_prev");
            $links[size $links] = { "class" => "previous", "item" => """<a href="$prev.url">$prev.caption</a>""" };
        }
 
        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 ( $p.view == "entry" ) {
            var Link next = $e->get_link("nav_next");
            $links[size $links] = { "class" => "next", "item" => """<a href="$next.url">$next.caption</a>""" };
        }
 
        print_module_list($links);
    }
 
    close_module();
}