[personal profile] ex_awakened208 posting in [community profile] style_system
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.

Date: 2012-12-18 02:09 am (UTC)
foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
From: [personal profile] foxfirefey
This is totally possible, but requires S2 tinkering--what is your level of experience with that? (So I know how to target.)

Date: 2012-12-18 10:41 pm (UTC)
foxfirefey: A picture of a hand where inked stick figures hug across fingers with a heart above them. (hearts)
From: [personal profile] foxfirefey
Aw, you've used S2 Cookbook stuff, yay. And yes! So basically, if I gave you a theme layer override to put in, you would be just fine with that, I think?

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!

Date: 2012-12-19 06:42 am (UTC)
foxfirefey: A fox colored like flame over an ornately framed globe (Default)
From: [personal profile] foxfirefey
Alrighty, looks like this does the trick:

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?

Date: 2012-12-20 12:13 am (UTC)
foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
From: [personal profile] foxfirefey
whoops! Yes, you're right, sorry. Okay, I have refactored the code to put prev/nav links for all recent/day/month/entry pages:

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.)

Date: 2012-12-20 03:40 am (UTC)
foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
From: [personal profile] foxfirefey
Of course I do not mind! That is a pretty astute question! I will do my best to answer it, but feel free to tell me to rephrase things that aren't understandable.

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!

Date: 2012-12-20 07:00 am (UTC)
foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
From: [personal profile] foxfirefey
Beneath RecentPage is just FriendsPage--you can see the hierarchy of the objects here. There's a page that explains more about the language here.

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.

Date: 2012-12-21 04:19 am (UTC)
foxfirefey: A picture of a hand where inked stick figures hug across fingers with a heart above them. (hearts)
From: [personal profile] foxfirefey
Thank YOU for working with native DW layouts!

Head-scratcher

Date: 2012-12-20 11:44 pm (UTC)
marahmarie: (M In M Forever) (Default)
From: [personal profile] marahmarie
If that hierarchy is literal it's rather strange (which is not a critique so much as a statement of complete befuddlement at it).

I always thought the hierarchy should flow more like this:

Page >
equal in hierarchy to
FriendsPage >
which would both own
RecentPage >
with the following descendants
TagsPage
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)
foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
From: [personal profile] foxfirefey
For the most part, object inheritance goes from the more general, all-encompassing class down to the more specific ones. So, Page is the umbrella over them all, because it is the most generic. A RecentPage is a page that lists recent entries, it's next. A FriendsPage is pretty much on the level of a recent page, really, but it has the tweak of displaying entries from others instead of recent entries in a journal, and reading and network pages use it. It inherits a lot of the code from the RecentPage, so that's its ancestor. Other pages are a lot more different from each other, so for the most part they inherit directly from the main Page (which is controlling basic layout stuff, layout out module areas and headers, etc). The exception is EntryPreviewPage, which is ALMOST like an EntryPage but with a preview, so that's what it inherits from.

Re: Head-scratcher

Date: 2012-12-21 05:49 am (UTC)
marahmarie: (M In M Forever) (Default)
From: [personal profile] marahmarie
OK, I had to really wrap my mind around that for a minute, but of course that's exactly right. Page (as in Page) can control anything so Friends page can't inherit directly from it since Page gives it no specific structure to work with (it needs RecentPage to build off of for that).

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. :)
Edited (typos) Date: 2012-12-21 05:52 am (UTC)

Date: 2012-12-20 11:54 pm (UTC)
marahmarie: (M In M Forever) (Default)
From: [personal profile] marahmarie
Is it because I already have custom navlink code in my theme layer that putting the prev/next in the navlinks is not working? My code is here:
http://www.dreamwidth.org/customize/advanced/layersource?id=116552&fmt=html

Date: 2012-12-21 12:15 am (UTC)
foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
From: [personal profile] foxfirefey
Yes, the function can only be used once. Replace both of them with this:

# 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();
}
Edited Date: 2012-12-21 12:16 am (UTC)

Date: 2012-12-21 01:29 am (UTC)
marahmarie: (M In M Forever) (Default)
From: [personal profile] marahmarie
♥ I'm in the middle of changing [community profile] css_code's CSS around but will hop back to my DW shortly to try this out - thanks!

(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.
Edited Date: 2012-12-21 01:57 am (UTC)

Profile

Dreamwidth style system discussion

October 2025

S M T W T F S
   1 234
567891011
12131415161718
19202122232425
262728293031 

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 3rd, 2026 07:31 am
Powered by Dreamwidth Studios