{"id":373,"date":"2005-06-06T00:15:22","date_gmt":"2005-06-06T05:15:22","guid":{"rendered":"http:\/\/www.nikolasschiller.com\/blog\/index.php\/the-daily-render-sort\/"},"modified":"2008-09-26T23:26:22","modified_gmt":"2008-09-27T03:26:22","slug":"the-daily-render-sort","status":"publish","type":"page","link":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/the-daily-render-sort\/","title":{"rendered":"The Daily Render Sort"},"content":{"rendered":"<div id=\"content\">\n<p>< ?php\n$posts_per_page = '100';\n$category_exclude = '-21';\n$defaultorderby = 'post_date';\n$defaultorder = 'DESC';\n\ndefine('NL', \"\\n\");\n\nfunction show_year_select() {\n    global $wpdb, $tableposts, $m;\n    $m = substr($m,0,4);\n    $years = $wpdb->get_col(&#8220;SELECT DISTINCT YEAR(post_date) as year FROM $tableposts ORDER BY year ASC&#8221;);<br \/>\n    $output .= &#8216;<option value=\"\">All Years<\/option>&#8216;.NL;<br \/>\n    foreach ($years as $year) {<br \/>\n        $output .= &#8216;<option value=\"'.$year.'\"';\n        if ($year == $m) {\n            $output .= ' selected=\"selected\"';\n        }\n        $output .= '>&#8216;.$year.&#8217;<\/option>&#8216;;<br \/>\n    }<br \/>\n    $output  = &#8216;<select name=\"m\">&#8216;.NL.$output.&#8217;<\/select>&#8216;.NL;<br \/>\n    echo $output;<br \/>\n}<\/p>\n<p>function show_author_select() {<br \/>\n    global $wpdb, $tableusers, $author;<br \/>\n    $users = $wpdb->get_results(&#8220;SELECT * FROM $tableusers WHERE user_level > 0&#8221;, ARRAY_A);<br \/>\n    $output .= &#8216;<option value=\"\">All Authors<\/option>&#8216;.NL;<br \/>\n    foreach ($users as $user) {<br \/>\n        $output .= &#8216;<option value=\"'.$user['ID'].'\"';\n        if ($user['ID'] == $author) {\n            $output .= 'selected=\"selected\"';\n        }\n        $output .= '>&#8216;.$user[&#8216;user_nickname&#8217;].&#8217;<\/option>&#8216;.NL;<br \/>\n    }<br \/>\n    $output = &#8216;<select name=\"author\">&#8216;.NL.$output.&#8217;<\/select>&#8216;.NL;<br \/>\n    echo $output;<br \/>\n}<\/p>\n<p>function show_orderby_select() {<br \/>\n    global $orderby;<br \/>\n    $orderby = explode(&#8216; &#8216;, $orderby);<br \/>\n    $orderby = $orderby[0];<br \/>\n    if ($orderby == &#8216;date&#8217;) {<br \/>\n       $output .= &#8216;<option value=\"date\" selected=\"selected\">Date<\/option>&#8216;.NL;<br \/>\n    } else {<br \/>\n       $output .= &#8216;<option value=\"date\">Date<\/option>&#8216;.NL;<br \/>\n    }<br \/>\n    if ($orderby == &#8216;title&#8217;) {<br \/>\n       $output .= &#8216;<option value=\"title\" selected=\"selected\">Title<\/option>&#8216;.NL;<br \/>\n    } else {<br \/>\n       $output .= &#8216;<option value=\"title\">Title<\/option>&#8216;.NL;<br \/>\n    }<br \/>\n    if ($orderby == &#8216;category&#8217;) {<br \/>\n       $output .= &#8216;<option value=\"category\" selected=\"selected\">Category<\/option>&#8216;.NL;<br \/>\n    } else {<br \/>\n       $output .= &#8216;<option value=\"category\">Category<\/option>&#8216;.NL;<br \/>\n    }<br \/>\n    $output = &#8216;<select name=\"orderby\" onchange=\"Choose(this)\">&#8216;.NL.$output.&#8217;<\/select>&#8216;.NL;<br \/>\n    echo $output;<br \/>\n}<\/p>\n<p>function show_order_select() {<br \/>\n    global $order;<br \/>\n    if ($order == &#8216;ASC&#8217;) {<br \/>\n       $output .= &#8216;<option value=\"ASC\" selected=\"selected\">Ascending<\/option>&#8216;.NL;<br \/>\n    } else {<br \/>\n       $output .= &#8216;<option value=\"ASC\">Ascending<\/option>&#8216;.NL;<br \/>\n    }<br \/>\n    if ($order == &#8216;DESC&#8217;) {<br \/>\n       $output .= &#8216;<option value=\"DESC\" selected=\"selected\">Descending<\/option>&#8216;.NL;<br \/>\n    } else {<br \/>\n       $output .= &#8216;<option value=\"DESC\">Descending<\/option>&#8216;.NL;<br \/>\n   }<br \/>\n   $output = &#8216;<select name=\"order\" id=\"asc_desc\">&#8216;.NL.$output.&#8217;<\/select>&#8216;.NL;<br \/>\n   echo $output;<br \/>\n}<\/p>\n<p>function archive_header($before=&#8221;, $after=&#8221;) {<br \/>\n    global $post, $orderby, $month, $previous, $siteurl, $blogfilename, $archiveheadstart, $archiveheadend, $category_name;<br \/>\n    $siteurl = get_settings(&#8216;siteurl&#8217;);<br \/>\n    $blogfilename = get_settings(&#8216;blogfilename&#8217;);<br \/>\n    $orderby = explode(&#8216; &#8216;, $orderby);<br \/>\n    $orderby = $orderby[0];<br \/>\n    if (&#8216;date&#8217; == $orderby || empty($orderby)) {<br \/>\n        $thismonth = mysql2date(&#8216;m&#8217;, $post->post_date);<br \/>\n        $thisyear = mysql2date(&#8216;Y&#8217;, $post->post_date);<br \/>\n        $thisdate = $thisyear.$thismonth;<br \/>\n        if ($thisdate != $previous) {<br \/>\n            $thismonth = mysql2date(&#8216;m&#8217;, $post->post_date);<br \/>\n            $output .= &#8216;<strong><\/p>\n<p><a href=\"'.$siteurl.'\/'.$blogfilename.'?m='.$thisdate.'\">&#8216;.$month[$thismonth].&#8217; &#8216;.$thisyear.&#8217;<\/a><\/strong>&#8216;;<br \/>\n        }<br \/>\n        $previous = $thisdate;<br \/>\n    } elseif (&#8216;title&#8217; == $orderby) {<br \/>\n        preg_match(&#8216;\/[a-z0-9]{1}\/i&#8217;, $post->post_title, $match);<br \/>\n        $thisletter = ucfirst($match[0]);<br \/>\n        if ($thisletter != $previous) {<br \/>\n            $output .= &#8220;<\/p>\n<p>&#8220;.$thisletter;<br \/>\n        }<\/p>\n<p>        $previous = $thisletter;<br \/>\n    } elseif (&#8216;category&#8217; == $orderby) {<br \/>\n        $thiscategory = $category_name;<br \/>\n        if ($thiscategory != $previous) {<br \/>\n            $output .= &#8216;<\/p>\n<p><strong><a href=\"'.$siteurl.'\/'.$blogfilename.'?cat='.$thiscategory.'\">&#8216;.get_catname($thiscategory).&#8217;<\/a><\/strong>&#8216;;<br \/>\n        }<br \/>\n        $previous = $thiscategory;<br \/>\n    }<br \/>\n    if (!empty($output)) {<br \/>\n        $output = $before.$output.$after.NL;<br \/>\n        echo $output;<br \/>\n    }<br \/>\n}<\/p>\n<p>function archive_date($format=&#8217;Y-m-d H:i:s&#8217;) {<br \/>\n    global $post;<br \/>\n    echo mysql2date($format, $post->post_date);<br \/>\n}<\/p>\n<p>?><\/p>\n<p><script language=\"javascript\" type=\"text\/javascript\">\nfunction Choose(whichSort) {\n    if (whichSort.selectedIndex == 2) {\n        document.getElementById('asc_desc').selectedIndex = 1;\n    } else {\n        document.getElementById('asc_desc').selectedIndex = 0;\n    }\n}\n<\/script><\/p>\n<p>< ?php\n\/\/Make sure categories get parsed out, they are deprecated in wp-blog-header.php\nif ($_POST[\"orderby\"] == 'category') {\n    global $author, $m;\n    $orderby = 'category';\n    if ($_POST[\"order\"] == '') $order = \"DESC\";\n    else $order = $_POST[\"order\"];\n    $year = '' . intval($_POST[\"m\"]);\n    $m = $year;\n    $author = ''.intval($_POST[\"author\"]);\n    if (empty($author)) {\n        $whichauthor='';\n    } else {\n        $author = ''.urldecode($author).'';\n        $author = addslashes_gpc($author);\n        if (stristr($author, '-')) {\n            $eq = '!=';\n            $andor = 'AND';\n            $author = explode('-', $author);\n            $author = ''.intval($author[1]);\n        } else {\n            $eq = '=';\n            $andor = 'OR';\n        }\n        $author_array = explode(' ', $author);\n        $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]);\n        for ($i = 1; $i < (count($author_array)); $i = $i + 1) {\n            $whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]);\n        }\n        $whichauthor .= ')';\n    }\n\n    \/\/ Author stuff for nice URIs\n\n    if ('' != $author_name) {\n        if (stristr($author_name,'\/')) {\n            $author_name = explode('\/',$author_name);\n            if ($author_name[count($author_name)-1]) {\n            $author_name = $author_name[count($author_name)-1];#no trailing slash\n            } else {\n            $author_name = $author_name[count($author_name)-2];#there was a trailling slash\n            }\n        }\n        $author_name = preg_replace('|[^a-z0-9-]|', '', strtolower($author_name));\n        $author = $wpdb->get_var(&#8220;SELECT ID FROM $tableusers WHERE user_nicename='&#8221;.$author_name.&#8221;&#8216;&#8221;);<br \/>\n        $whichauthor .= &#8216; AND (post_author = &#8216;.intval($author).&#8217;)&#8217;;<br \/>\n    }<br \/>\n    if (!empty($year)) $where .= &#8216; AND YEAR(post_date)=&#8217; . $year;<br \/>\n    if (!empty($whichauthor)) $where .= $whichauthor;<br \/>\n    ?><\/p>\n<p>    Show Archives Sorted By:<\/p>\n<form action=\"<?php getenv('PHP_SELF') ?>&#8221; method=&#8221;post&#8221;><br \/>\n    < ?php show_orderby_select() ?><br \/>\n    < ?php show_order_select() ?><br \/>\n    < ?php show_year_select() ?><br \/>\n    <input type=\"submit\" name=\"submit\" value=\"sort\"\/><br \/>\n    <\/form>\n<p>    < ?php\n    global $category_exclude;\n    $cat = $category_exclude;\n    if (stristr($cat,'-')) {\n        \/\/ Note: if we have a negative, we ignore all the positives. It must\n        \/\/ always mean 'everything \/except\/ this one'. We should be able to do\n        \/\/ multiple negatives but we don't :-(\n        $eq = '!=';\n        $andor = 'AND';\n        $cat = explode('-',$cat);\n        $cat = intval($cat[1]);\n    }\n    $cat_array = explode(' ',$cat);\n\n    $dogs = $wpdb->get_results(&#8220;SELECT * FROM $tablecategories WHERE cat_ID != $cat_array[0] ORDER BY cat_name $order&#8221;);<br \/>\n    foreach ($dogs as $catt) {<br \/>\n        $categories = $wpdb->get_results(&#8220;SELECT * FROM $tablepost2cat WHERE category_id = $catt->cat_ID&#8221;);<br \/>\n        if ($categories) {<br \/>\n            foreach ($categories as $post2category) {<br \/>\n                $posts = $wpdb->get_results(&#8220;SELECT * FROM $tableposts WHERE $post2category->post_id = ID&#8221;.$where);<br \/>\n                \/\/$category_realname = $wpdb->get_row(&#8220;SELECT cat_name FROM $tablecategories WHERE cat_ID = $post2category->category_id&#8221;);<br \/>\n                \/\/print_r($category_realname);<br \/>\n                global $category_name;<br \/>\n                $category_name = $post2category->category_id;<br \/>\n                if ($posts) {<br \/>\n                    foreach ($posts as $post) {<br \/>\n                        start_wp();<br \/>\n                        archive_header(&#8216;<\/p>\n<h3>&#8216;, &#8216;<\/h3>\n<ul class=\"archive\">&#8216;);<br \/>\n                        archive_date(&#8216;m-d-Y h:iA&#8217;) ?>: <a href=\"<?php echo get_permalink($post->ID) ?>&#8221; rel=&#8221;bookmark&#8221; title=&#8221;Permanent Link: < ?php the_title(); ?>&#8220;>< ?php the_title(); ?><\/a><br \/>\n                        < ?php\n\n                    }\n                }\n            }\n        }\n    }\n}\nelse {\n\tif ($_POST[\"orderby\"] == '') {\n\t\t$monthnum = date(\"m\");\n\t\t$year = date(\"Y\");\n\t\t}\n\t$cat = $category_exclude;\n    require_once ('wp-blog-header.php');\n    \/\/ echo $request;\n    \tif ($monthnum) {\n    \t\t$orderby = '';\n\t\t}\n    ?><\/p>\n<p>    Show Archives Sorted By:<\/p>\n<form action=\"<?php getenv('PHP_SELF') ?>&#8221; method=&#8221;post&#8221;><br \/>\n    < ?php show_orderby_select() ?><br \/>\n    < ?php show_order_select() ?><br \/>\n    < ?php show_year_select() ?><br \/>\n    <input type=\"submit\" name=\"submit\" value=\"sort\"\/><br \/>\n    <\/form>\n<p>    < ?php if ($posts) { foreach ($posts as $post) { start_wp(); ?><br \/>\n    < ?php \/\/print_r($post); ?><br \/>\n    < ?php archive_header('<\/ul>\n<h3>&#8216;, &#8216;<\/h3>\n<\/ul>\n<ul class=\"archive\">&#8216;) ?><br \/>\n    < ?php archive_date('m-d-Y h:iA') ?>: <a href=\"<?php echo get_permalink($post->ID) ?>&#8221; rel=&#8221;bookmark&#8221; title=&#8221;Permanent Link: < ?php the_title(); ?>&#8220;>< ?php the_title(); ?><\/a><br \/>\n    < ?php } }\n    }?>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>< ?php $posts_per_page = '100'; $category_exclude = '-21'; $defaultorderby = 'post_date'; $defaultorder = 'DESC'; define('NL', \"\\n\"); function show_year_select() { global $wpdb, $tableposts, $m; $m = substr($m,0,4); $years = $wpdb->get_col(&#8220;SELECT DISTINCT YEAR(post_date) as year FROM $tableposts ORDER BY year ASC&#8221;); $output .= &#8216;All Years&#8216;.NL; foreach ($years as $year) { $output .= &#8216;&#8216;.$year.&#8217;&#8216;; } $output = &#8216;&#8216;.NL.$output.&#8217;&#8216;.NL; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-373","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/wp-json\/wp\/v2\/pages\/373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=373"}],"version-history":[{"count":0,"href":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/wp-json\/wp\/v2\/pages\/373\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nikolasschiller.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}