?

Log in

[user/theme] - [smoothsailing] - [multi-level tags in sidebar] - S2 Layers [entries|archive|friends|userinfo]
S2 Layers

[ website | advanced customization ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| how to post tags page ]
[affiliated communities| fblayers ]

[user/theme] - [smoothsailing] - [multi-level tags in sidebar] [Feb. 13th, 2007|07:07 pm]
S2 Layers

s2layers

[kunzite1]
[Tags|, , , ]

this code is a quick'n'dirty conversion of s2flexisquared's s2flexisquares multi-level tags in sidebar.
the following set commands should be added to your user layer and replace any that are currently in there.
set layout_sidebox_profile_visibility     = "1";
set layout_sidebox_latestmonth_visibility = "2";
set layout_sidebox_links_visibility       = "3";
set layout_sidebox_summary_visibility     = "4";
set layout_sidebox_multisearch_visibility = "5";
set layout_sidebox_freetext_2_visibility  = "6";
set layout_sidebox_tags_visibility        = "hide";
the following function overrides should be placed into a theme layer. if you are using one of the system-provided theme layers, you'll need to move those set commands for the colors into your user layer, create a new theme layer, place this code into it, and attach the new theme layer to your style.
function Page::print_custom_head()
{

    """
    <style type="text/css">

    /* List Alignment */
    /* Styles to ensure that the tag list is correctly aligned beneath the sidebox title */
    li.tagBox  {padding-left: 0;    margin-left: 0; list-style: none;}
    ul.tagList {padding-left: 0;    margin-left: 0; list-style: none;}
    li.tagItem {padding-left: 15px;                 list-style: none;}
    
    /* Vertical Scroll */
    /* Need to shrink the list width to prevent horizontal scrollbar in Firefox. */
    /* Note this won't prevent it if your tags are super long, it will only */
    /* prevent it from displaying unnecessarily. */
    ul.tagList {width: 90%;}

    </style>
    """;
}

function Page::lay_print_sidebar_freetextbox_2() {

#####   Config   #####

  # Specify your delimiter.  One char only -- extra chars get truncated.
  var string delimiter = ":";

  # Do you want to show the tag use counts? Set to true or false.
  var bool show_count = true;

  # Specify the text to show just before the use count, if any.
  var string pre_count = "[";

  # Specify the text to show just after the use count, if any.
  var string post_count = "]";

  # Specify the title of your tag box!
  var string tag_title = "Tags";

##### End Config #####

  var Page p = get_page();
  var string list = "";    
  
  if (size $p->visible_tag_list() > 0) { 
    if ($delimiter->length() > 1) {
      $delimiter = $delimiter->substr(0, 1);
    } 

    var string[] closing_html;
    var string[] prev_tags;
    var int tag_list_pos = 0;
    var string tier_code = "";
    $closing_html[0] = "";
    $prev_tags[0] = "";
    foreach var TagDetail t ($p->visible_tag_list()) {
      var string[] tags;
 
      if ($t.name) {  
        # mt:20050623
        # Split tags into array on delimiter. Oh god, my kingdom
        # for a function.  Stolen shamelessly from lj-user rane500.
        var int array_counter = 0;
        var string buffer = "";
        foreach var string char ($t.name) {
          if($char == $delimiter) {
            $tags[$array_counter] = $buffer;
            $array_counter = $array_counter + 1;
            $buffer = "";
          }
          else {
            $buffer = $buffer + $char;
          } 
        }  
        $tags[$array_counter] = $buffer;
  
        var int pos = 0;
        foreach var string tier($tags) {
          if (size $closing_html <= $pos) {
            # mt:20050623
            # $closing_html keeps track of html that is used to close off open
            # lists.  Its length must be kept >= to that of the current tag.
            $closing_html[$pos] = "";
          }   

          if (size $prev_tags <= $pos) {
            # mt:20050625
            # The current tag has more tiers than the previous tag.  To avoid array
            # ref errors when comparing the current tier to the previous one (which
            # is non-existent, of course) add empty string to $prev_tags.
            $prev_tags[$pos] = "";
          }
    
          # mt:20050623
          # If we're on a tag's last tier, we need to return a link to the tag,
          # otherwise plain text is returned.
          if (size $tags == ($pos + 1)) {
            $tier_code = """<a rel="tag" href="$t.url">$tier</a>""";
            if ($show_count) {
              $tier_code = $tier_code + """&nbsp;${pre_count}${t.use_count}${post_count}""";
            }
          }
          else {
            $tier_code = """$tier""";
          }

          # mt:20050625
          # $prev_tags stuffed with dummy empty string when it has fewer tiers than 
          # current tag.
          if ($prev_tags[$pos] == "") {     
            # mt:20050623
            # The current tag has more tiers than the previous tag, so a new
            # list must be opened.  
            if (($tag_list_pos == 0) and ($pos == 0)) {
              # mt:20061216
              # The outermost ul is supplied later by print_sidebar_box,
              # so omit it from this stage.
              $list = $list + """<li class="sbaritem">$tier_code""";                  
              $closing_html[$pos] = "</li>";  
            }
            else {
              $list = $list + """<ul><li class="sbaritem">$tier_code""";                  
              $closing_html[$pos] = "</li></ul>";
            }
          }
          elseif ($tags[$pos] != $prev_tags[$pos]) {   
            # mt:20050623
            # The current tag's tier is not the same as the previous tag's tier of  
            # the same level.  This means we may need to close some lists.
            var int i = size $closing_html;
            foreach var string html ($closing_html) {
              if ($i > $pos) {
                $list = $list + $closing_html[$i];                                 
                # mt:20050623: As we append the closing code, pop it off the array.
                $closing_html[$i] = "";
              }
              $i--;
            }                    
 
            if ($closing_html[$pos] == "") {          
              # mt:20050623
              # This is the first tier at this level, so open list.
              $list = $list + """<ul><li class="sbaritem">$tier_code""";
              $closing_html[$pos] = "</li></ul>";
            }
            else {              
              # mt:20050623
              # There have already been tiers added at this level, so just close the previous
              # list item before adding the new tier.
              $list = $list + """</li><li class="sbaritem">$tier_code""";
            }                    
          }
          else {
            # mt:20050623
            # The current tag's tier is exactly the same as the previous tag's tier at
            # this same level.  It has already been included in the list, so do nothing.
          }  
          # mt:20050623: Moving on to next tier in this tag!
          $pos++;
        }
        $prev_tags = $tags;           
      }        
      # mt:20050623: Next tag in the list!
      $tag_list_pos++;
    }  

    # mt:20050623
    # All the tags have been added so close all outstanding lists.
    var int i = 0;
    var string remaining_html = "";
    foreach var string html ($closing_html) { 
      if ($html != "") {
        $remaining_html = $html + $remaining_html;
        $closing_html[$i] = "";
      }
      $i++;
    }
    $list = $list + $remaining_html;
  }

  if ($list != ""){
    $this->lay_print_sidebox_top($tag_title);
    print """<ul>""" + $list + """</ul>""";
    $this->lay_print_sidebox_bottom();
  }
}
linkReply

Comments:
[User Picture]From: agneson9
2007-02-14 04:59 am (UTC)
s'good. thank you.
(Reply) (Thread)
[User Picture]From: kunzite1
2007-02-14 05:32 am (UTC)
yay. :D
(Reply) (Parent) (Thread)
[User Picture]From: zimena
2007-05-07 12:49 pm (UTC)
I've tried making this work a few times already, but so far I'm having no luck. I know next to nothing about LJ coding, so I'm basically just copying this code, and hoping that it works. But - as far as I understand, the multilevel tags list should go in the Freetext 2 box, right? Therefore, the "normal" tags list is set to "hide"?

...however, my Freetext 2 box is just empty, and I have no clue what I'm doing wrong. Except perhaps that I don't have that MANY tags that comply with this format yet. I wanted to make it work, and then go and reorganize the tags for all the old posts. Therefore, I have only a couple of tags with a :-delimiter in them right now.

Would anyone be able to help, please?
(Reply) (Thread)
(Deleted comment)
[User Picture]From: _workinprogress
2007-05-27 01:25 am (UTC)
never mind.
I found where I messed up.

...

thank you, by the way ^_^
should I be giving credit somewhere?
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2007-05-27 11:38 am (UTC)
good to know that you figured it out.

don't worry about credit. i provide this as a free service and don't require credit. however, i ask that you don't pass it off as your own.
(Reply) (Parent) (Thread)
[User Picture]From: scotchsour
2007-09-23 03:45 pm (UTC)
I'm trying to use this for GJ and there is a one line problem.

Compile error: line 328, column 59: Can't find member 'use_count' in Tag

this is the line:
328: $tier_code = $tier_code + """ ${pre_count}${t.use_count}${post_count}""";

I know there is differences betwween LJ and GJ but is there another code in GJ for use_count to see it if can save and compile properly?

Thank you for any help.
(Reply) (Thread)
[User Picture]From: sparklpocalypse
2012-03-18 12:10 pm (UTC)
Figured I'd ask before I started poking at this -- is there a way to get this to work on the tags page in Smooth Sailing, instead of in the sidebar? If not, I can totally live with the built-in tag cloud, but this is nifty and I kinda want it. :D
(Reply) (Thread)