Difference between revisions of "Template:comic"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(fix template for when the titletext parameter is specified without a value)
 
(111 intermediate revisions by 14 users not shown)
Line 1: Line 1:
<includeonly><!--
+
<includeonly><metadesc>explain xkcd is a wiki dedicated to explaining the webcomic xkcd. Go figure.</metadesc><!--
--><table class="{{{bodyclass|}}}" cellspacing="5"
 
          style="background-color: #FFFFFF; border: 1px solid #AAAAAA; color: black; font-size: 88%; line-height: 1.5em;
 
                margin: 0.5em 0 0.5em 1em; padding: 0.2em; text-align: center; width:98%; {{{bodystyle|}}}"><!--
 
  
  ### Navigation bar (previous, next...) ###
+
  Create the 'box' (table) around the comic template
  
   --><tr><td><!--
+
   --><table class="comic-content {{#if:{{{bodyclass|}}}|{{{bodyclass}}}|}}" cellspacing="5" style="background-color: #FFFFFF;
 +
      border: 1px solid #a2a9b1; color: black; font-size: 88%;
 +
      line-height: 1.5em; margin: 0.5em 0 0.5em 1em; padding: 0.2em;
 +
      text-align: center; width:98%; {{#if:{{{bodystyle|}}}|{{{bodystyle}}}|}}"><!--
 +
 
 +
      Comic title in '''BOLD''' and in small caps, like on xkcd.com
 +
    -->{{#if:{{{title|}}}|<tr><td style="font-size: 21px; font-variant: small-caps; font-weight: 800; padding-bottom:11px; padding-top:15px;">{{{title}}}</td></tr>|<tr><td style="font-size: 21px; font-variant: small-caps; font-weight: 800; padding-bottom:11px; padding-top:15px;"></td></tr>}}<!--
 +
 
 +
    Display the original title and link to it just before the navigation
 +
    -->{{#if:{{{ogtitle|}}}|<tr><td style="padding-bottom:12px; padding-top:0px; font-size: 19px;" class="plainlinks"><!--
 +
 
 +
    Replace the default label for {{{ogtitle}}} (which is "Original title") with custom {{{ogttlabel}}} if
 +
    provided, and replace all spaces with &nbsp;s so it looks cute
 +
    -->''[[LiveJournal#O{{!}}{{#if:{{{ogttlabel|}}}|{{#replace:{{{ogttlabel}}}| |&nbsp;}}|<span title="Learn why the original xkcd comics were in a different order!">Original&nbsp;title</span>}}]]:'' <!--
 +
 
 +
    --><span style="font-variant: small-caps; font-weight: 800; font-size: 21px;">[{{{oglink|<span style="color:red"><br><br>ERROR: LINK MISSING.<br><br>PLEASE ADD <code><nowiki>|OGLINK=URL</nowiki></code> TO THE PAGE!</span><br><br>}}} {{{ogtitle}}}]</span></td></tr>}}<!--
 +
 
 +
      This table will contain a table row (tr) and cell (td)
 +
    --><tr><td><!--
 +
 
 +
      Now make an unordered list which will display as the first navigation bar, above the image
 
     --><ul style="text-align: center; margin-bottom: 10px;" class="no-link-underline"><!--
 
     --><ul style="text-align: center; margin-bottom: 10px;" class="no-link-underline"><!--
  
       ### If there is an article for the comic prior to this one, create a "prev" ###
+
       Generate the |< and prev buttons, but only if {{{number}}} exists and is greater than 0
 +
    -->{{#ifexpr:{{{number|-1}}}>1<!--
  
      -->{{#ifexist:{{#expr:{{{number}}} - 1}}<!--
+
        {{{number}}} is greater than 1; make a list item and put a button in it that links to #1
 
       -->|<li style="background-color: #6E7B91;
 
       -->|<li style="background-color: #6E7B91;
                      border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
+
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
                      display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
+
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
                      margin: 0 4px; padding: 1.5px 12px;"><!--
+
              margin: 0 4px; padding: 1.5px 0;"><!--
          -->[[{{#expr:{{{number}}} - 1}}|<span style="color: #FFFFFF;">&lt; Prev</span>]]<!--
+
              link to #1
        --></li><!--
+
        -->[[1: Barrel - Part 1|<span style="color: #FFFFFF; padding: 0 12px; white-space: nowrap;" title="">&#124;&lt;</span>]]</li><!--
      -->|<li style="display: inline; font-size: 16px; margin: 0 4px; padding: 1.5px 12px;"><!--
+
 
          -->&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!--
+
        We're not done here yet, let's make the back button
         --></li><!--
+
        --><li style="background-color: #6E7B91;
      -->}}<!--
+
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;"><!--
 +
 
 +
              Link to the previous comic
 +
          -->[[{{#expr:{{{number|2}}}-1}}|<span style="color: #FFFFFF; padding: 0 12px;" title="">&lt;&nbsp;Prev</span>]]</li><!--
 +
 
 +
              {{{number}}} doesn't exist or is less than 1; just put non-breaking spaces here
 +
              -->|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}<!--
 +
 
 +
         Regardless of {{{number}}}, we need to make the comic date, link etc.<!--
 +
        --><li style="background-color: #6E7B91;
 +
          border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
          display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
          margin: 0 4px; padding: 1.5px 0;"
 +
          class="plainlinks"><!--
  
      ### Create a centre button with comic number, date (if exists) and link ###
+
          [ and ] makes an external link, vs. [[ and ]] which are internal only.
 +
          Depending whether {{{number}}} exists or not, toggle between using wide link mode or number link mode.
 +
          Wide link mode requires {{{lappend}}} to be set, while {{{ldomain}}} can default to www
 +
          -->[{{#ifexpr:{{{number|-1}}}>=1<!--
  
      --><li style="background-color: #6E7B91;
+
          Comic number is probably valid, use number link mode
                    border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
+
          -->|https://xkcd.com/{{{number}}}<!--
                    display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 
                    margin: 0 4px; padding: 1.5px 12px;"
 
            class="no-xkcd-favicon"><!--
 
        -->[http://www.xkcd.com/{{{number}}}/ <!--
 
        --><span style="color: #FFFFFF;">Comic &#35;{{{number}}} {{#if:{{{date|}}}|({{{date}}})}}</span>]<!--
 
      --></li><!--
 
  
      ### If there is an article for the comic following this one, create a "next" ###
+
          Comic number is invalid or doesn't exist, use wide link mode
 +
          -->|https://{{{ldomain|www}}}.xkcd.com/{{{lappend}}}}}<!--
  
      -->{{#ifexist:{{#expr:{{{number}}} + 1}}<!--
+
          Generate the title, with date if it exists
      -->|<li style="background-color: #6E7B91;
+
          --><span style="color: #FFFFFF; padding: 0 12px;" title="Open this comic on xkcd.com"><!--
                      border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
+
          -->{{#ifexpr:{{{number|-1}}}>= 1|&#35;|{{#if: {{{date|}}}||Go&nbsp;to&nbsp;}}Comic}}{{{number|}}}{{#if:{{{date|}}}|&nbsp;({{#replace:{{{date}}}| |&nbsp;}})}}</span>]</li><!--
                      display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
+
 
                      margin: 0 4px; padding: 1.5px 12px;"><!--
+
        Now make the next and >| buttons, provided the comic number exists
          -->[[{{#expr:{{{number}}} + 1}}|<span style="color: #FFFFFF;">Next &gt;</span>]]<!--
+
        -->{{#ifexist:{{#expr:{{{number|-2}}}+1}}<!--
         --></li><!--
+
 
       -->|<li style="display: inline; font-size: 16px; margin: 0 4px; padding: 1.5px 12px;"><!--
+
        Check if this is the LATESTCOMIC. If it is, then don't display the "Next" and >| buttons.
          -->&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!--
+
        -->|{{#ifexpr:{{LATESTCOMIC}}-{{{number|1}}}>0<!--
         --></li><!--
+
 
      -->}}<!--
+
        Comic number is not the latest, generate the buttons
    --></ul><!--
+
        -->|<li style="background-color: #6E7B91;
  --></td></tr><!--
+
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;"><!--
 +
        -->[[{{#expr:{{{number|0}}}+1}}{{!}}<span style="color: #FFFFFF; padding: 0 12px;" title="">Next&nbsp;&gt;</span>]]</li><!--
 +
 
 +
         Make a button that points to LATESTCOMIC (which is of course the latest comic)
 +
        --><li style="background-color: #6E7B91;
 +
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;"><!--
 +
              -->[[{{LATESTCOMIC}}{{!}}<span style="color: #FFFFFF; padding: 0 12px; white-space: nowrap;" title="">&gt;&#124;</span>]]</li><!--
 +
 
 +
        Comic number (plus one) is the latest, so don't show the buttons.
 +
        The spaces below are needed to make the other buttons look like they're centered even if a portion of the buttons are missing
 +
        -->|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}|          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}<!--
 +
    --></ul></td></tr><!--
 +
 
 +
    Now that the nav bar has been generated, display the rest if given.
 +
 
 +
    Display the (optional) text just before the image
 +
    -->{{#if:{{{before|}}}|<tr><td style="padding-bottom:10px">{{{before}}}</td></tr>}}<!--
 +
 
 +
    Almost done; just need to display the image, title text, and a bit more
 +
    --><tr><td><!--
 +
 
 +
    {{{custom}}} will replace the image with whatever it contains if it exists
 +
    -->{{#if: {{{custom|}}}|{{{custom|}}}<!--
 +
 
 +
    Now that we know we're not going to replace the image, let's display it if it exists
 +
    -->|{{#if:{{{image|}}}|[[File:{{{image|}}}|{{{imagesize|}}}|{{{titletext|}}}]]}}}}<!--
 +
 
 +
    {{{imagesize}}} will allow the comic to be shrunk if it's especially large
 +
 
 +
    {{{noexpand}}} will hide the "Click comic to enlarge" notice
 +
    -->{{#ifeq:{{{noexpand|}}}|true||
 +
        {{#if:{{{imagesize|}}}|<br />[Click comic to enlarge]}}
 +
      }}<!--
 +
 
 +
    Add the title text underneath the comic.
 +
    --><br /><span style="margin-top: 0.9em; margin-bottom: {{#if:{{{ognumber|}}}|0.5|0}}em; display:inline-block; font-size: 120%; <!--
 +
    Use the custom Title Text STYLE (ttstyle) if given
 +
    -->{{{ttstyle|}}}"><span class="plainlinks" title=""><!--
 +
    -->''[[Title text|Title&nbsp;text]]:''</span> {{#if:{{{titletext|}}}|{{{titletext}}}|[[:Category:No title text|none]]}}<!--
 +
    --></span></td></tr><!--</table>
 +
 
 +
      Ok, the upper navigation bar is done! Now, let's make the lower WHITE navbar.
 +
      You probably haven't seen this, check out comic [[10]] and others.
 +
      This is only displayed if {{{ognumber}}} is specified, otherwise it's replaced by the "gray" navbar (we'll make it below).
 +
      This table will contain a table row (tr) and cell (td)
 +
    --><tr><td><!--
 +
 
 +
      Now make an unordered list which will display as the navigation bar
 +
    --><ul style="text-align: center; margin-top:2px; margin-bottom:{{#if:{{{ognumber|}}}|20px|10px}};" class="no-link-underline"><!--
 +
 +
      Generate the |< and prev buttons, but only if {{{ognumber}}} IS GIVEN and is not 1
 +
    -->{{#if:{{{ognumber|}}}|{{#ifexpr:{{{ognumber|1}}}!=1<!--
 +
 
 +
        {{{ognumber}}} is given and not 1, so make a list item and put a button in it that links to #7
 +
       -->|<li style="background-color: #FFFFF;
 +
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;"><!--
 +
 
 +
              Now link to #7. Why #7 and not #1? → see [[LiveJournal]]
 +
        -->[[7: Girl sleeping (Sketch -- 11th grade Spanish class)|<span style="color: #6E7B91; padding: 0 12px; white-space: nowrap;" title="">&#124;&lt;</span>]]</li><!--
 +
 
 +
        Let's make the back button!
 +
PIPE REMOVED--><li style="background-color: #FFFFF;
 +
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;"><!--
 +
 
 +
              Link to the previous comic
 +
          -->[[{{{ogprev|<span style="color:red">ERROR: PREVIOUS NUMBER MISSING.<br><br>PLEASE ADD <code><nowiki>|OGPREV=NUMBER</nowiki></code> TO THE PAGE!<br><br>&nbsp;&nbsp;&nbsp;</span>}}}|<span style="color: #6E7B91; padding: 0 12px;" title="">&lt;&nbsp;Prev&nbsp;&#35;{{{ogprev}}}</span>]]</li><!--
 +
 
 +
              {{{ognumber}}} is 1, so let's put non-breaking spaces here
 +
              -->|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!--
 +
 
 +
          Close up shop-->}}}}<!--
 +
 
 +
          Since we have {{{ognumber}}}, we need to say the original comic number at the center.
 +
      -->{{#if:{{{ognumber|}}}|<!--{{#ifexpr:{{{ognumber|1}}}!=1|--><!--
 +
 
 +
          Ok {{ognumber}} is not 1, go wild!
 +
      --><li style="background-color: #FFFFFF;
 +
          border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
          display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
          margin: 0 4px; padding: 1.5px 0;" class="plainlinks"><!--
 +
 
 +
          Depending on whether {{{ognumber}}} is 1 or not, toggle between using wide link mode or number link mode.
 +
          Wide link mode requires {{{lappend}}} to be set, while {{{ldomain}}} can default to www
 +
          --><!--
 +
          NOT USING THESE - [{{#ifexpr:{{{number|-1}}}>=1
 +
          NOT USING THESE - Comic number is probably valid, use number link mode
 +
          |https://xkcd.com/{{{number}}}
 +
          NOT USING THESE - Comic number is invalid or doesn't exist, use wide link mode
 +
          |https://{{{ldomain|www}}}.xkcd.com/{{{lappend}}}}}      (This would need another two curly because added another IF statement)
 +
 
 +
          Ok now generate the number, with ognote if it exists, or else it defaults to "(Original Order)"
 +
          -->[[LiveJournal#G|<span style="color: #6E7B91; padding: 0 12px;" title="Click to learn why the original xkcd comics were in a different order!"><!--
 +
         
 +
          Add ognote in parenthesis
 +
          -->&#35;{{{ognumber|}}}&nbsp;{{#if:{{{ognote|}}}|({{#replace:{{{ognote}}}| |&nbsp;}})|(Original&nbsp;Order)}}<!-- Comic&nbsp;&#35;{{{ognumber|}}}&nbsp;<u>(Original&nbsp;order)</u>
 +
          --></span>]]}}</li><!--
 +
 
 +
         Now make the next and >| buttons, provided the {{{ognumber}}} exists
 +
      -->{{#ifexist:{{#expr:{{{ognumber|-2}}}+1}}<!--
 +
 
 +
        Check if this is 55 (which is the latest LiveJournal comic). If it is 55, then don't display the "Next" and >| buttons.
 +
        Why #52 and not #LATESTCOMIC? → see [[LiveJournal]]
 +
        -->|{{#ifexpr:52-{{{ognumber|1}}}>0<!--
 +
 
 +
        {{ognumber}} IS NOT 52, generate the Next and >| buttons
 +
        -->|<li style="background-color: #FFFFF;
 +
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;"><!--
 +
        -->[[{{{ognext|<span style="color:red"><br><br>ERROR: NEXT NUMBER MISSING.<br><br>PLEASE ADD <code><nowiki>|OGNEXT=NUMBER</nowiki></code> TO THE PAGE!<br><br>&nbsp;&nbsp;&nbsp;</span>}}}|<span style="color: #6E7B91; padding: 0 12px;" title="">&#35;{{{ognext}}}&nbsp;Next&nbsp;&gt;</span>]]</li><!--
 +
 
 +
        Make a button that points to 55 (which is the latest LiveJournal comic)
 +
        --><li style="background-color: #FFFFF;
 +
              border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
              display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
              margin: 0 4px; padding: 1.5px 0;"><!--
 +
              -->[[55: Useless{{!}}<span style="color: #6E7B91; padding: 0 12px; white-space: nowrap;" title="">&gt;&#124;</span>]]</li><!--
 +
 
 +
        Comic number (plus one) is the latest, so don't show the buttons
 +
        The spaces below are needed to make the other buttons look like they're centered even if a portion of the buttons are missing
 +
-->|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;              }}|}}</ul></td></tr><!--
 +
 
 +
      Ok, that row's done. But it'll be hidden if the comic is one of the first xkcd comics.
 +
      So, let's make the lower GRAY row. This is hidden if {{{ognumber}}} is specified, because it's replaced by the "white" navbar above.
 +
      This will be shown on almost all comics.
 +
      This table will contain a table row (tr) and cell (td)
 +
      -->{{#ifexist: {{{ognumber}}} | <!-- If ognumber is provided, hide the entire block, if not show it
 +
      -->|<tr><td><!--
 +
 
 +
      Now make an unordered list which will display as the navigation bar
 +
      --><ul style="text-align: center; margin-top:-7px; margin-bottom:15px;" class="no-link-underline"><!-- CHATG
  
  ### Comic title ###
+
      Generate the |< and prev buttons, but only if {{{number}}} exists and is greater than 1
 +
      -->{{#ifexpr:{{{number|-1}}}>1<!--
  
  -->{{#if:{{{title|}}}|<tr><td style="font-size: 20px; padding-bottom:10px"><!--
+
    {{{number}}} is greater than 1; make a list item and put a button in it that links to #1
    -->'''{{{title}}}'''<!--
+
  -->|<li style="background-color: #6E7B91;
  --></td></tr>}}<!--
+
          border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
          display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
          margin: 0 4px; padding: 1.5px 0;"><!--
 +
          link to #1
 +
    -->[[1: Barrel - Part 1|<span style="color: #FFFFFF; padding: 0 12px; white-space: nowrap;" title="">&#124;&lt;</span>]]</li><!--
  
  ### Comic image and title text ###
+
    We're not done here yet, let's make the back button
 +
    --><li style="background-color: #6E7B91;
 +
          border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
          display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
          margin: 0 4px; padding: 1.5px 0;"><!--
  
  --><tr><td><!--
+
          Link to the previous comic
  -->{{#if:{{{image|}}}|[[File:{{{image|}}}|{{{imagesize|}}}|{{{titletext|}}}]]}}<!--
+
      -->[[{{#expr:{{{number|2}}}-1}}|<span style="color: #FFFFFF; padding: 0 12px;" title="">&lt;&nbsp;Prev</span>]]</li><!--
  -->{{#if:{{{imagesize|}}}|<br />[Click comic to enlarge]}}<!--
 
  -->{{#if:{{{titletext|}}}|<br /><span style="{{{captionstyle|}}}"><span style="color:grey">Title text:</span> {{{titletext}}}</span>}}<!--
 
  --></td></tr><!--
 
--></table><!--
 
  
  ### Add categories to comic based on date field ###
+
If {{{number}}} is valid, we need to make the RANDOM COMIC LINK in the center
 +
--><li style="background-color: #6E7B91;
 +
    border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
    display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
    margin: 0 4px; padding: 1.5px 0;" class="plainlinks"><!--
  
-->{{#ifeq:{{NAMESPACE}}|{{ns:10}}||<!-- (no categorization on the Template namespace)
+
    Generate the RANDOM COMIC LINK in the center.
  -->{{#ifeq:{{FULLPAGENAME}}|{{int:mainpage}}||<!-- (no categorization when transcluded into the main page)
+
     The "Category:All pages" includes all comics, including the extra ones.
     -->[[Category:Comics|{{Num4|{{{number}}}}}]]<!--
+
     -->[[Special:RandomInCategory/All pages|<span style="color: #FFFFFF; padding: 0 12px;" title=""><!--
     -->{{#if:{{{date|}}}|<!--
+
     -->Random&nbsp;Explanation</span>]]</li><!--
      -->[[Category:Comics from {{#time:Y|{{{date}}}}}]]<!--
 
      -->[[Category:Comics from {{#time:F|{{{date}}}}}]]<!--
 
      -->[[Category:{{#time:l|{{{date}}}}} Comics]]<!--
 
     -->}}<!--
 
  -->}}<!--
 
-->}}<!--
 
  
  ### DOCUMENTATION ###
+
    Now make the next and >| buttons, provided the comic number exists
 +
    -->{{#ifexist:{{#expr:{{{number|-2}}}+1}}<!--
  
--></includeonly><noinclude>
+
    Check if this is the LATESTCOMIC. If it is, then don't display the "Next" and >| buttons.
This is the basic infobox-style header template used to display [[xkcd]] comics on their own pages, including the comic number (with external link to xkcd), publication date, title, comic image, and title text.
+
    -->|{{#ifexpr:{{LATESTCOMIC}}-{{{number|0}}}>0<!--
  
== Sample ==
+
    Comic number is not the latest, so generate the Next and >| buttons
 +
    -->|<li style="background-color: #6E7B91;
 +
          border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
 +
          display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
 +
          margin: 0 4px; padding: 1.5px 0;"><!--
 +
    -->[[{{#expr:{{{number|0}}}+1}}{{!}}<span style="color: #FFFFFF; padding: 0 12px;" title="">Next&nbsp;&gt;</span>]]</li><!--
  
The following is a sample usage of this template:
+
    Make a button that points to LATESTCOMIC (which is of course the latest comic)
{{comic
+
    --><li style="background-color: #6E7B91;
| number    = 16
+
          border: 1.5px solid #333333; border-radius: 3px 3px 3px 3px; box-shadow: 0 0 5px 0 gray;
| date      = January 1, 2006
+
          display: inline; font-size: 16px; font-variant: small-caps; font-weight: 600;
| title    = Monty Python -- Enough
+
          margin: 0 4px; padding: 1.5px 0;"><!--
| image    = monty_python.jpg
+
          -->[[{{LATESTCOMIC}}{{!}}<span style="color: #FFFFFF; padding: 0 12px; white-space: nowrap;" title="">&gt;&#124;</span>]]</li><!--
| imagesize = 350px
 
| titletext = I went to a dinner where there was a full 10 minutes of Holy Grail quotes exchanged, with no context, in lieu of conversation.  It depressed me badly.
 
}}
 
  
== Usage ==
+
      Instead here the comic number (plus one) is the latest, so don't show the Next buttons (there are no next comics)
 +
      The spaces below are needed to make the other buttons look like they're centered even if a portion of the buttons are missing
 +
        -->|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}|          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}}<!--
 +
       
 +
      Here {{{number}}} doesn't exist or is less than 1; just put nothing here
 +
        -->|}}<!--
 +
--></ul></td></tr>}}</table><!--
  
<pre>{{comic
+
     Add the comics to the automatic categories.
| number    =
 
| date      =
 
| title     =
 
| image    =
 
| imagesize =
 
| titletext =
 
}}</pre>
 
  
=== Notes ===
+
    Put this page in categories by number. The padding ensures that #9 comes before #10
 +
    It otherwise sorts 'alphanumerically'; since the first character of "10" is "1", it would normally be placed before "9" even though it should be placed after
 +
    The padding turns each into 0009 and 0010 etc. Now, since "0" is less than "1", #9 gets sorted before #10.
 +
    -->{{#ifexpr:{{{number|-1}}}>=1|{{DEFAULTSORT: {{padleft:{{{number}}}|4}}}}|<!--
 +
    -->}}<!--
  
* At least the number, title and image are required.
+
    Only categorise if the page is in the main namespace
* The date should be written in the form: January 1, 2006
+
    -->{{#ifeq:{{NAMESPACE}}|{{ns:0}}<!--
* The imagesize field is optional for larger comics.
 
** The comic's '''width''' will be limited to the set size. Format must be in pixels (eg: "350px")
 
** The comic's '''height''' may be set by adding an 'x' to the start (eg: "x350px")
 
** Warning: If the size is larger than the image, the image will be stretched.
 
  
The above sample is produced by the following code:
+
    Don't try to categorise the Main Page nor the extra comics
 +
    -->|{{#ifeq:{{FULLPAGENAME}}|{{int:mainpage}}||{{#ifeq:{{{extra|}}}|yes|[[Category:Extra comics]][[Category:All pages]]|<!--
  
<pre>{{comic
+
    Alright, start putting it in the appropriate date categories
| number    = 16
+
    -->[[Category:All comics]][[Category:All pages]]<!--
| date     = January 1, 2006
+
    -->{{#if:{{{date|}}}|[[Category:Comics from {{#time:Y|{{{date}}}}}]]    <!-- Years
| title    = Monty Python -- Enough
+
    -->[[Category:Comics from {{#time:F|{{{date}}}}}]]                      <!-- Months
| image     = monty_python.jpg
+
     -->[[Category:{{#time:l|{{{date}}}}} comics]]                            <!-- Weekdays
| imagesize = 350px
+
    -->}}}}}}|}}<!--
| titletext = I went to a dinner where there was a full 10 minutes of Holy Grail quotes exchanged, with no context, in lieu of conversation.  It depressed me badly.
+
    --></includeonly><noinclude><!--
}}</pre>
 
  
[[Category:Templates]]
+
          DOCUMENTATION-->{{:Template:comic/doc}}[[Category:Templates]]</noinclude>
</noinclude>
 

Latest revision as of 15:09, 4 July 2025

The template {{comic}} has an associated sandbox, available at Template:comic/sandbox.


This is the basic infobox-style header template used to display xkcd comics on their own pages, including the comic number (with external link to xkcd), publication date, title, comic image, and title text.

(edit documentation)

Usage

{{comic
| number    =
| date      =
| title     =
| ognumber  =
| oglink    =
| ogttlabel =
| ogtitle   =
| ogprev    =
| ognote    =
| ognext    =
| before    =
| image     =
| custom    =
| imagesize =
| noexpand  =
| titletext =
| ttstyle   =
| bodystyle =
| bodyclass =
| extra     =
| ldomain   =
| lappend   =
}}
Ambox notice.png The new parameters are undocumented! There's some info about them in the code.
ogttlabel = optional
ognumber  = 
ogprev    = required if ognumber given, otherwise throws an error
ognote    = optional
ognext    = required if ognumber given, otherwise throws an error
Parameter Usage Description
number Required in normal circumstances The comic's basic information. In normal circumstances, these should always be defined.
title Required in normal circumstances
image Required in normal circumstances
date Optional; omit if unreleased or undated The date the comic was first published and should be written in the form mmmm d, yyyy. (Full month name, day number without digit padding, 4-digit year. Example: January 1, 2006). If the comic has no date or has not been released, it should be omitted.
ognumber Optional; only used for early comics Must always be used together for the early xkcd comics, not when Randall changes the title of an existing comic. Note that if ognumber is given, some parameters are required.
oglink
ogtitle
before Optional; used for long comics Used to insert text before the comic, usually to insert a link to skip to the explanation on extremely large comics like 1732: Earth Temperature Timeline or for the comic itself if it's just text like Blue Eyes. The text provided to this parameter is placed on the line between the title and the image. This parameter is optional. The wikitext used to jump to the ==Explanation== is [[#Explanation|↓ Skip to explanation ↓]].
imagesize Optional; limits image display size Limits the size of the image in pixels.
  • To limit the width, simply list the width. E.g.: 350px
  • To limit the height, prepend an "x" to the desired height. E.g.: x400px

Note that, if the imagesize is larger than the image, the image will be stretched.

noexpand Optional; used when imagesize limits display Boolean to hide the "Click to enlarge" button, usually when using imagesize.
custom Optional; overrides image Replaces the comic image with custom text or content.
titletext Optional; sets title text Sets the title text of the comic.
ttstyle Optional; styles title text Sets the CSS style of the titletext span element.
bodystyle Optional; sets wrapper style Sets the inline CSS style of the outer comic container.
bodyclass Optional; sets wrapper class Sets the HTML class attribute of the outer comic container.
extra Optional; boolean When set to yes, adds the page to the Extra comics category.
lappend Required if number is missing The part of the link appended to xkcd.com/ in "wide link mode". Required when number is not set.
ldomain Optional; changes link domain Sets the subdomain for the link (e.g., blog for blog.xkcd.com). Defaults to www. For example, if the link is to a blog post (blog.xkcd.com), ldomain should be set to blog. The resulting link when using lappend and optionally ldomain is:

https://ldomain.xkcd.com/lappend

Example 1

Suspension Bridge
As a first step, they can put in a secondary deck, to help drivers try it out and find out how fun the jumps are. After a while no one will use the old flat deck and they can remove it.
Title text: As a first step, they can put in a secondary deck, to help drivers try it out and find out how fun the jumps are. After a while no one will use the old flat deck and they can remove it.

The example above is produced by the following code:

{{comic
| number    = 3048
| date      = February 7, 2025
| title     = Suspension Bridge
| image     = suspension_bridge_2x.png
| imagesize = 362x365px
| noexpand  = true
| titletext = As a first step, they can put in a secondary deck, to help drivers try it out and find out how fun the jumps are. After a while no one will use the old flat deck and they can remove it.
}}

Example 2

Pi Equals
My most famous drawing, and one of the first I did for the site
Title text: My most famous drawing, and one of the first I did for the site
Warning: Default sort key "0010" overrides earlier default sort key "3048".

The example above is produced by the following code:

{{comic
| ognumber    = 10
| ognumber    = 10
| date      = September 30, 2005
| title     = Pi Equals
| oglink    = https://web.archive.org/web/20070927001941/http://xkcd-drawings.livejournal.com/?skip=40#:~:text=8%3A44%20pm-,Pi%20equals,-(4%20Comments
| ogtitle   = Pi equals
| image     = pi.jpg
| titletext = My most famous drawing, and one of the first I did for the site
}}

Tests

Air Fact
'Wow, that must be why you swallow so many of them per year!' 'No, that's spiders. You swallow WAY more ants.'
Title text: 'Wow, that must be why you swallow so many of them per year!' 'No, that's spiders. You swallow WAY more ants.'
Warning: Default sort key "3070" overrides earlier default sort key "0010".
Suspension Bridge
As a first step, they can put in a secondary deck, to help drivers try it out and find out how fun the jumps are. After a while no one will use the old flat deck and they can remove it.
Title text: As a first step, they can put in a secondary deck, to help drivers try it out and find out how fun the jumps are. After a while no one will use the old flat deck and they can remove it.
Warning: Default sort key "3048" overrides earlier default sort key "3070".


Pi Equals
My most famous drawing, and one of the first I did for the site
Title text: My most famous drawing, and one of the first I did for the site
Warning: Default sort key "0008" overrides earlier default sort key "3048".
Pi Equals
My most famous drawing, and one of the first I did for the site
Title text: My most famous drawing, and one of the first I did for the site
Warning: Default sort key "0010" overrides earlier default sort key "0008".