kunzite (kunzite1) wrote in component_help,
kunzite
kunzite1
component_help

how to add custom links to the header, programmer-style

this advances upon shrinking and centering and is in reference to bubbleforest's comment here.
function page_layout(Page p) {
  # Set this to the width that you want both the navbar (if it exists) and the whole journal to be
  # may be percentage (70%) or number of pixels (700px).
  var string k1Swidth = "70%";

  # Start the html document and print the head section which controls the page title, stylesheet information,
  # server supplied head content, and custom header informtion from the print_custom_head function.
  var string title = $p->title();
  """
  <html>
  <head>
    <link rel="stylesheet" href="$p.stylesheet_url" type="text/css"/>
    $p.head_content
    """; $p->print_custom_head(); """
    <title>$title</title>
  </head>
  """;
  
  # Start the body section of the html document which controls the visible parts of the page.
  """<body style="text-align:center;">""";

  # If you want a picture to be at the top of your journal, edit and decomment this section.
  # """<div align="center"><img src="url here" alt="caption here" title="caption here too" /></div>""";

  if($k1Swidth != "") {
    """<table style="border: 0px; margin: auto; padding: 0px; width:$k1Swidth;"><tr><td>""";
  }

  # Print the navigation bar if it is needed. This can be incorporated into any other tutorials which override
  # the page_layout() function, and should be placed immediately after the <body> tag above.
  if (not $*comp_navbar or $*comp_state=="none") {
    # set the order of the views
    # component's default is recent, friends, archive (calendar), userinfo
    var string[] views_order   = ["recent",
                                  "friends",
                                  "archive",
                                  "userinfo"
                                 ];
    # set the link text for the views
    var string{} lang_viewname = {"recent"   => $*nav_entries_text,
                                  "friends"  => $*nav_friends_text,
                                  "archive"  => $*nav_calendar_text,
                                  "userinfo" => $*nav_info_text
                                 };
    # make a variable for the url of the view
    var string view_url;
    # make a variable for the link text for the view
    var string viewname;
    """    <div class="header">\n""";
    # cycle thru the views
    foreach var string v ($views_order) {
      $view_url = $p.view_url{$v};
      # if friends or archive (calendar) add a trailing slash to the url cuz it doesnt have one for some reason
      if($v == "friends" or $v == "archive") {
        $view_url = $view_url + "/";
      }
      # if userinfo add &mode=full
      if($v == "userinfo") {
        $view_url = $view_url + "&mode=full";
      }
      # print out the link
      """      <span class="header-item"><a href="$view_url">$lang_viewname{$v}</a></span>\n""";
      # if we're done printing the friends view link lets work on custom friends pages
      if($v == "friends") {
        # get the url to the friends page w/out the trailing slash so we can play with it later
        $view_url = $p.view_url{$v};
        # set the urls to append to the friends view url
        var string[] url  = [
                             "?show=p",
                             "?show=c",
                             "?show=y",
                             "?show=cy"
                            ];
        # set the link text that goes with the above urls
        var string[] text = [
                             "people",
                             "communities",
                             "syndicaton",
                             "communities + syndication"
                            ];
        # if you messed up the sizing of your arrays this will make it so s2 doesnt die on you
        var int size = (size($url) > size($text)) ? size($text) : size($url);
        # cycle thru the links
        foreach var int i (0 .. $size - 1) {
          """      <span class="header-item"><a href="$view_url/$url[$i]">$text[$i]</a></span>\n""";
        }
      }
    }
    # add the website link if youve got one
    if ($p.journal.website_url != "") {
      var string website_name = ($p.journal.website_name != "") ? $p.journal.website_name : $*text_website_default_name;
      """      <span class="header-item"><a href="$p.journal.website_url">$website_name</a></span>\n""";
    }
    """      """;
    # add the prev/next links
    $p->lay_viewspec_nav();  # prints previous / next links including arrow images
    """	    </div>""";
  }
  # Print a spacer at the top of the page above the components and main area.
  """<div><img src="$*PALIMGROOT/component/clear.gif" width="1" height="3" alt="" border="0"></div>""";

  # Start the table which lays out the components and main area in side-by-side layout.
  """
  <table width="100%" cellspacing="0" cellpadding="0" valign="top">
    <tr valign="top" width="100%">
      <td width="3">
        <img src="$*PALIMGROOT/component/clear.gif" width="3" height="1" alt="" border="0">
      </td>
  """;
  
  # If the components are supposed to be on the left side of the page, then print them, followed by a column
  # with a spacer which is to seperate the components and the main area.
  if ($*comp_state == "left") {
    print_my_components($p);
    """
    <td width="3">
     <img src="$*PALIMGROOT/component/clear.gif" width="3" height="1" alt="" border="0">
    </td>
    """;
  }

  # Print the main area of the page.
  print_my_entries($p, $title);

  # If the components are supposed to be on the right side of the page, then first print a column with a spacer 
  # and then print the components after the spacer. 
  if ($*comp_state == "right") {
    """
    <td width="3">
     <img src="$*PALIMGROOT/component/clear.gif" width="3" height="1" alt="" border="0">
    </td>
    """;
    print_my_components($p);
  }

  # Finish off the table for the body
  """
      <td width="3">
        <img src="$*PALIMGROOT/component/clear.gif" width="3" height="1" alt="" border="0">
      </td>
    </tr>
  </table>
  """;

  if($k1Swidth != "") {
    """</td></tr></table>""";
  }

  # End the body section and end the html document
  """
  </body>
  </html>
  """;
}
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 27 comments