{"id":3707,"date":"2009-09-03T19:20:12","date_gmt":"2009-09-04T02:20:12","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3707"},"modified":"2009-09-06T13:48:01","modified_gmt":"2009-09-06T20:48:01","slug":"change-graphics-based-on-season","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/php\/change-graphics-based-on-season\/","title":{"rendered":"Change Graphics Based on Season"},"content":{"rendered":"

Function<\/h4>\n
<?php\r\n\r\nfunction current_season() {\r\n       \/\/ Locate the icons\r\n       $icons = array(\r\n               \"spring\" => \"images\/spring.png\",\r\n               \"summer\" => \"images\/summer.png\",\r\n               \"autumn\" => \"images\/autumn.png\",\r\n               \"winter\" => \"images\/winter.png\"\r\n       );\r\n\r\n       \/\/ What is today's date - number\r\n       $day = date(\"z\");\r\n\r\n       \/\/  Days of spring\r\n       $spring_starts = date(\"z\", strtotime(\"March 21\"));\r\n       $spring_ends   = date(\"z\", strtotime(\"June 20\"));\r\n\r\n       \/\/  Days of summer\r\n       $summer_starts = date(\"z\", strtotime(\"June 21\"));\r\n       $summer_ends   = date(\"z\", strtotime(\"September 22\"));\r\n\r\n       \/\/  Days of autumn\r\n       $autumn_starts = date(\"z\", strtotime(\"September 23\"));\r\n       $autumn_ends   = date(\"z\", strtotime(\"December 20\"));\r\n\r\n       \/\/  If $day is between the days of spring, summer, autumn, and winter\r\n       if( $day >= $spring_starts && $day <= $spring_ends ) :\r\n               $season = \"spring\";\r\n       elseif( $day >= $summer_starts && $day <= $summer_ends ) :\r\n               $season = \"summer\";\r\n       elseif( $day >= $autumn_starts && $day <= $autumn_ends ) :\r\n               $season = \"autumn\";\r\n       else :\r\n               $season = \"winter\";\r\n       endif;\r\n\r\n       $image_path = $icons[$season];\r\n\r\n       echo $image_path;\r\n}\r\n\r\n?><\/code><\/pre>\n

Usage<\/h4>\n
<img src=\"<?php current_season() ?>\" alt=\"\" \/><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Function <?php function current_season() { \/\/ Locate the icons $icons = array( “spring” => “images\/spring.png”, “summer” => “images\/summer.png”, “autumn” => “images\/autumn.png”, “winter” => “images\/winter.png” ); \/\/ What is today’s date – number $day = date(“z”); \/\/ Days of spring $spring_starts = date(“z”, strtotime(“March 21”)); $spring_ends = date(“z”, strtotime(“June 20”)); \/\/ Days of summer $summer_starts = […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3233,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":4242,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/display-a-tag-cloud\/","url_meta":{"origin":3707,"position":0},"title":"Display a Tag Cloud","date":"September 27, 2009","format":false,"excerpt":"The default sizing, if none supplied, for this function is \"pt\" which is a bit unusual and often unreliable so make sure you change that parameter to how you size fonts normally on your site. Less Weird Font Sizing Tag clouds accomplish their varied font sizes by applying inline styling\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3745,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/change-avatar-size\/","url_meta":{"origin":3707,"position":1},"title":"Change Avatar Size","date":"September 4, 2009","format":false,"excerpt":"The wp_list_comments function has a parameter to change the default (48px) size to anywhere between 0 and 80px. wp_list_comments('avatar_size=80');","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5975,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/exclude-this-from-selector\/","url_meta":{"origin":3707,"position":2},"title":"Exclude $(this) from Selector","date":"March 19, 2010","format":false,"excerpt":"Let's say you want to attach a click handler to every link on a page. The function for that click handler turns all the other links a different color. var $allLinks = $(\"a\"); $allLinks.click(function() { $allLinks.not(this).css(\"color\", \"red\"); }); You can use the .not() function to remove elements from a set,\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3260,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/id-the-body-based-on-url\/","url_meta":{"origin":3707,"position":3},"title":"ID the Body Based on URL","date":"May 19, 2010","format":false,"excerpt":"This would turn http:\/\/domain.tld\/blog\/home into \"domaintldbloghome\", which is far more specific. It also will remove \".php\" file extensions and the default WordPress search parameter. More Secure Method function curr_virtdir($echo=true){ $url = explode('\/',$_SERVER['REQUEST_URI']); $dir = $url[1] ? $url[1] : 'home'; \/\/ defaults to this if in the root $dir = htmlentities(trim(strip_tags($dir)));\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3335,"url":"https:\/\/css-tricks.com\/snippets\/jquery\/link-nudging\/","url_meta":{"origin":3707,"position":4},"title":"Link Nudging","date":"August 10, 2009","format":false,"excerpt":"$(\"a\").hover(function() { $(this).stop().animate({paddingLeft : \"10px\"},200); },function() { $(this).stop().animate({paddingLeft : \"0px\"},200); }); Make sure to change the selector to only target the links you want to have nudging, e.g. \"#sidebar ul li a\"","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":175418,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/loop-queryselectorall-matches\/","url_meta":{"origin":3707,"position":5},"title":"Loop Over querySelectorAll Matches","date":"July 14, 2014","format":false,"excerpt":"Let's look at some options for iterating over a NodeList, as you get back from running a document.querySelectorAll. We've written an updated article about this: A Bunch of Options for Looping Over querySelectorAll NodeLists. Not all browsers support forEach on NodeLists, but for those that do: buttons.forEach((button) => { button.addEventListener('click',\u2026","rel":"","context":"In \"forEach\"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3707"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3707"}],"version-history":[{"count":2,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3707\/revisions"}],"predecessor-version":[{"id":3902,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3707\/revisions\/3902"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3233"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3707"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}