Would it be possible to merge the "previous" and "next" links with the main navigation that has the "recent entries"/"read page"/"tags", etc links in it?
The end result I am looking for is a header navigation that goes in this order:
previous | recent entries | archive | read | tags | info | next
I would prefer if the previous/next links only show up if there are actually entries before/afterward.
I hope that was clear enough! Thanks in advance.
The end result I am looking for is a header navigation that goes in this order:
previous | recent entries | archive | read | tags | info | next
I would prefer if the previous/next links only show up if there are actually entries before/afterward.
I hope that was clear enough! Thanks in advance.
no subject
Date: 2012-12-18 02:09 am (UTC)no subject
Date: 2012-12-18 02:41 am (UTC)Thanks for helping!
no subject
Date: 2012-12-18 10:41 pm (UTC)So, let me know what you're base layout is, and I think I can go from there and get you some code that will work!
no subject
Date: 2012-12-19 01:23 am (UTC)no subject
Date: 2012-12-19 06:42 am (UTC)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(); }Can you try it out in a theme layer and see if it's what you want?
no subject
Date: 2012-12-19 10:35 am (UTC)( $p.view == "entry" )and wondered if that meant it would only show up on the page of an individual entry. I checked and that was where it was at. It was exactly what I was looking for except I wanted it to show for the recent entries page and the read page. Sorry I wasn't more clear!no subject
Date: 2012-12-20 12:13 am (UTC)code is here
(If there are pages you don't want that option on, you sound like you know how to cut out the parts that put them there, but if not let me know.)
no subject
Date: 2012-12-20 02:17 am (UTC)And now other people can find this code more easily too! :)
Quick question, if you don't mind. I didn't see a code that targeted the read page specifically in there, but I've checked that it works there too. Does
RecentPageinclude that by default? Just curious.no subject
Date: 2012-12-20 03:40 am (UTC)So basically, S2 is an object oriented language, and every page has its own Page object. Then all the other page types inherit from that original object. There's a bunch of hierarchy that happens. So, there's RecentPage that has the foundation for a page that's a list of recent entries, and there is FriendsPage (haha exposes our LJ origins) that inherits from that. So a FriendsPage is a RecentPage which is a Page, each one inheriting from the base of the parent object.
The code that is checking what kind of page it is (the "isa" part) will return true if the type of the object is one of the ancestors of the object, too. So when I go "isa RecentPage", it will say yes if it's a recent journal entries page (RecentPage) or if it is a reading or networkpage (FriendsPage). Does that make any sense?
If all you wanted was the short answer: yes, it includes it!
no subject
Date: 2012-12-20 06:23 am (UTC)So there's a Page, and beneath that is RecentPage and beneath RecentPage is FriendsPage and RecentPage? Does it get confusing when there's two RecentPage's? I guess this would make more sense if I knew more about the language, but do you have put in something specific to make sure it targets the right RecentPage?
no subject
Date: 2012-12-20 07:00 am (UTC)For the code that I gave you, I only need to check if the page we're on is a RecentPage, whether it's actually a RecentPage or a FriendsPage, because the variables I need from it all end up being the same. Sometimes that might not work! Sometimes you might need to know whether it is a specific view, or a specific object and not one that includes the children.
If it's about the specific object, there's a different type operator to use called "instanceof". For that one, if I did $p instanceof RecentPage, it wouldn't return true if $p was a FriendsPage.
If it's about the specific view, Page objects have a variable called "view" that can be used to check--I think that's what I was using previously when I was only doing the entries, something like
$p.view == "entry". In that case, view would be different from recent page, or the readig page, or the network page.no subject
Date: 2012-12-20 10:34 am (UTC)no subject
Date: 2012-12-21 04:19 am (UTC)Head-scratcher
Date: 2012-12-20 11:44 pm (UTC)I always thought the hierarchy should flow more like this:
Page
>
equal in hierarchy toFriendsPage
>
which would both ownRecentPage
>
with the following descendantsTagsPage
YearPage
MonthPage
DayPage
EntryPage
EntryPreviewPage
To my mind, that makes more sense. The way it is now, FriendsPage is a descendant of Page when they should be more or less equal in value because they hold and do the same thing! But maybe I'm just not able to wrap my mind around why FriendsPage should be a descendant of Recent...
Re: Head-scratcher
Date: 2012-12-21 04:23 am (UTC)Re: Head-scratcher
Date: 2012-12-21 05:49 am (UTC)I think the other thing that threw me off is I always thought Recent was literally the first direct descendant of Page (in other words, in the hierarchy, DayPage, EntryPage, EntryPreviewPage, IconsPage, MessagePage and MonthPage would never precede it). But this was probably more a bias of mine based on how I work through the code when I'm editing an entire layout (it goes like this: Recent/Friends-Network, Entry, Tags, Archive-Month-Day - I'm kind of OCD in that I have to edit each view in exactly that order) than a rational way to order the hierarchy.
Thanks for the further explanation, the specific code I needed and all your help. :)
no subject
Date: 2012-12-20 11:54 pm (UTC)http://www.dreamwidth.org/customize/advanced/layersource?id=116552&fmt=html
no subject
Date: 2012-12-21 12:15 am (UTC)# code by ninetydegrees/foxfirefey function print_module_navlinks() { 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>"; } } var string[] navlinks_order = []; var string{} navlinks_urls = {}; var string{} navlinks_text = {}; $navlinks_order = [ "userinfo", "tags", "archive", "journals", "communities", "networkpc", ]; $navlinks_urls = { "userinfo" => "$p.base_url/profile", "tags" => "$p.base_url/tag", "archive" => "$p.base_url/calendar", "journals" => "$p.base_url/read?show=P", "communities" => "$p.base_url/read?show=C", "networkpc" => "$p.base_url/network?show=PC", }; $navlinks_text = { "userinfo" => "About", "tags" => "All Tags", "archive" => "Archives", "journals" => "DW People", "communities" => "DW Places", "networkpc" => "DW Plains", }; open_module("navlinks", "", ""); var string[] links = []; if ( $prev_link ) { $links[size $links] = $prev_link; } 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>"""; } } if ( $next_link ) { $links[size $links] = $next_link; } print_module_list($links); close_module(); }no subject
Date: 2012-12-21 01:29 am (UTC)(And yeah, so my hunch was right - couldn't imagine what else it was.)
ETA: worked like a charm - and you wrote that up really quick.