{"id":140,"date":"2004-10-04T01:40:51","date_gmt":"2004-10-03T22:40:51","guid":{"rendered":"http:\/\/www.all-things-me.net\/blog\/archives\/2004\/10\/04\/ironing-and-folding-and-sorting-by-date"},"modified":"2010-08-12T02:06:58","modified_gmt":"2010-08-11T23:06:58","slug":"ironing-and-folding-and-sorting-by-date","status":"publish","type":"post","link":"https:\/\/www.all-things-me.net\/blog\/2004\/10\/04\/ironing-and-folding-and-sorting-by-date","title":{"rendered":"Ironing and folding and sorting by date"},"content":{"rendered":"<p>I added the <a href=\"http:\/\/wiki.wordpress.org\/NicerArchives\">Nicer Archives<\/a> code snippet from <a href=\"http:\/\/wiki.wordpress.org\/\">WP Wiki<\/a>. I tried to use the &#8220;upgraded&#8221; versions of it (from <a href=\"http:\/\/www.weblogtoolscollection.com\/\">Weblog Tools Collection<\/a>) but they borked &#8212; big time.<\/p>\n<p>When you enter the page, it shows the posts of the current year. Then you can sort the posts by date, title, or category; ascending or descending; and from all years or one year at a time (there is only one year, for now). The original script had a possibility sort by author but because there&#8217;s only me, I commented it out.<\/p>\n<p>Time format is date.month.year.<\/p>\n<p>On to <a href=\"\/blog\/archives.php\">the archives<\/a> &raquo;<\/p>\n<p>The calendar showed as January 2004 so I started to look for a way to remove it. Easier said than done. Well, not really, but I didn&#8217;t think of echoing the variable in my if-test to see what it&#8217;s out put was. This is what I wrote (first):<\/p>\n<blockquote class=\"php\"><p>&lt;?php $thispage = $_SERVER[&#8216;HTTP_HOST&#8217;].$PHP_SELF;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;if ($thispage != &#8220;<strong>www.mypage.xxx\/blog-folder\/pagename.php<\/strong>&#8220;) { ?&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!&#45;&#45; CALENDAR &#45;&#45;&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id=&#8221;calendar&#8221;&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php <a href=\"http:\/\/wiki.wordpress.org\/get_calendar\" target=\"_blank\">get_calendar<\/a>(); ?&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/li&gt;<br \/>\n&lt;?php } ?&gt;<\/p><\/blockquote>\n<p>http_host + php_self return the url of a php page a without the http (as that&#8217;d be the protocol)<\/p>\n<p>Then I tried what $_SERVER[&#8216;REQUEST_URI&#8217;] does and it echoed the path without the host. Nifty. Thus, I changed the code to<\/p>\n<blockquote class=\"php\"><p>&lt;?php $thispage = $_SERVER[&#8216;REQUEST_URI&#8217;];<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;if ($thispage != &#8220;<strong>\/blog-folder\/pagename.php<\/strong>&#8220;) { ?&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!&#45;&#45; CALENDAR &#45;&#45;&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id=&#8221;calendar&#8221;&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;?php <a href=\"http:\/\/wiki.wordpress.org\/get_calendar\" target=\"_blank\">get_calendar<\/a>(); ?&gt;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/li&gt;<br \/>\n&lt;?php } ?&gt;<\/p><\/blockquote>\n<p>[edit: Nov 22\/Dec 15, &#8217;04\/Jan 5, &#8217;05] I had an oddly titled post which messed up the archive. Well, not exactly *mess* but because it had an less-than sign at the beginning it was archived under L, but first alphabetically. After some testing, I figured out how to prevent this. <del>From the <a href=\"http:\/\/wiki.wordpress.org\/UpdatePostSlugs\">WP Wiki<\/a> I found a function <code>sanitize_title_with_dashes<\/code> which I used in the archive code, this is in the function archive_header:<\/del> This worked when my odd titles included only one starting with A. But when there was one with D, I noticed the code didn&#8217;t work. Why? Because it compares the first letter if the current title to the previous one and the query sorts the odd titles at first. Well, I took another approach to this. All odd titles will be categorized under # (I know it means &#8216;number&#8217; but here it&#8217;s just some non-alphabetic character). A new try, a * I had in one of the titles wouldn&#8217;t be recognized, probably because the line starting with preg_match matches only letters and numbers, so I changed that to match any one character (at the beginning). Hopefully this will prove working with my strange titles&#8230;<\/p>\n<blockquote class=\"php\"><p>elseif (&#039;title&#039; == $orderby) {<br \/>\n  preg_match(&#039;\/.{1}\/i&#039;, $post-&gt;post_title, $match);<br \/>\n  $thisletter = ucfirst($match[0]);<br \/>\n  <strong>if (!ctype_alpha($thisletter)) { $thisletter = &#039;#&#039;; }<\/strong><br \/>\n  if ($thisletter != $previous) {<br \/>\n    $output .= &quot;&lt;br\/&gt;&quot;.$thisletter;<br \/>\n  }<br \/>\n  $previous = $thisletter;<\/p><\/blockquote>\n<p>The highlighted part checks if the first letter of the title is NOT an alphabetic character, if it&#8217;s true that it&#8217;s NOT one, the letter will be a &#8216;#&#8217;. Now all the odd titles will be grouped at the beginning of the list of titles (or end if the order&#8217;s descending) . [\/edit]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I added the Nicer Archives code snippet from WP Wiki. I tried to use the &#8220;upgraded&#8221; versions of it (from Weblog Tools Collection) but they borked &#8212; big time. When you enter the page, it shows the posts of the current year. Then you can sort the posts by date, title, or category; ascending or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,9,18],"tags":[],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-tweaks","category-updates","category-wordpress"],"_links":{"self":[{"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":2,"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":1458,"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/posts\/140\/revisions\/1458"}],"wp:attachment":[{"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.all-things-me.net\/blog\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}