{"id":738,"date":"2015-02-26T10:08:41","date_gmt":"2015-02-26T14:08:41","guid":{"rendered":"http:\/\/tech.creed3.com\/?p=738"},"modified":"2015-03-14T11:20:15","modified_gmt":"2015-03-14T15:20:15","slug":"wp-post-date-fun","status":"publish","type":"post","link":"https:\/\/tech.creed3.com\/?p=738","title":{"rendered":"WP Post Date Fun"},"content":{"rendered":"<p><img decoding=\"async\" style=\"margin: 0 4px 4px 0;\" alt=\"\" src=\"images\/stories\/wordpress-logo-simplified-rgb.png\" width=\"100\" align=\"left\" border=\"0\" \/>Using CSS it&#8217;s easy to spice up your WordPress posts by adding some fun styling to the post date. &nbsp;I&#8217;m certain this translates well into other blog or CMS systems, but I&#8217;m just focusing on WordPress with this one.<!--more--><\/p>\n<p>For this example I&#8217;ll show how I created the pseudo old fashioned paper date stamp for this blog. &nbsp;This post assumes you already know what you&#8217;re doing when it comes to editing your WP theme files. &nbsp;If you don&#8217;t any developer (myself included of course) can easily make this modification for you.<\/p>\n<p>First, start in your theme index.php file. &nbsp;Find the loop where your posts are parsed and displayed. &nbsp;Somewhere in there you should find something like this which displays the post date:<\/p>\n<pre><code>&lt;?php the_time('M') ?&gt; &lt;?php the_time('d') ?&gt; &lt;?php the_time('Y') ?&gt;<\/code><\/pre>\n<p>Now, depending oh how this is formatted in relation to the post title, you may need to shift things around a bit. &nbsp;This date stamp works best if it&#8217;s positioned to the left of the post title rather than what is commonly seen as right under the post title. &nbsp;To do this I created a DIV to hold the post date and title grouped together in this manner of putting the date stamp to the left of the title. &nbsp;The modified layout looks like this:<\/p>\n<pre><code>&lt;div class=\"postheader\"&gt;\r\n\t&lt;div id=\"postdate\"&gt;\r\n\t\t&lt;div id=\"pdmonth\"&gt;&lt;?php the_time('M') ?&gt;&lt;\/div&gt;\r\n\t\t&lt;div id=\"pdday\"&gt;&lt;?php the_time('d') ?&gt;&lt;\/div&gt;\r\n\t\t&lt;div id=\"pdyear\"&gt;&lt;?php the_time('Y') ?&gt;&lt;\/div&gt;\r\n\t&lt;\/div&gt;\r\n\t&lt;div class=\"posthead\"&gt;\r\n\t\t&lt;div class=\"posttitle\"&gt;&lt;?php the_title(); ?&gt;&lt;\/div&gt;\r\n\t\t&lt;div class=\"postbyline\"&gt;by &amp;nbsp;&lt;?php the_author() ?&gt;&lt;\/div&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt;<\/code><\/pre>\n<p>Note: the post title is usually enclosed by an <i>a href<\/i> link to the post, which I have removed here for clarity.<\/p>\n<p>As you can see there is the <i>postheader<\/i> DIV which encases the post date DIV and post title DIV. &nbsp;All of the formatting work is handled by the CSS as such:<\/p>\n<pre><code>.postheader {\r\n\tdisplay: block;\r\n\twidth: 100%;\r\n\toverflow: hidden;\r\n}\r\n.posthead {\r\n\tfloat: left;\r\n\tpadding-left:10px;\r\n}\r\n#postdate {\r\n\tdisplay: block;\r\n\tfloat: left;\r\n\twidth: 40px;\r\n\theight: 40px;\r\n\tmargin: 0;\r\n\tpadding: 0;\r\n\ttext-align: center;\r\n\tborder: 1px solid black;\r\n\tborder-radius: 20px;\r\n\t-moz-border-radius: 20px;\r\n\t-webkit-border-radius: 20px;\r\n\tbackground: #efefef;\r\n}\r\n#pdmonth {\r\n\tbackground: transparent;\r\n\tfont-size: 7pt;\r\n\tfont-weight: normal;\r\n\tfont-family: Verdana;\r\n\ttext-transform: uppercase;\r\n\tcolor: #303030;\r\n}\r\n#pdday {\r\n\tbackground: transparent;\r\n\tfont-size: 12pt;\r\n\tfont-weight: bold;\r\n\tfont-family: Georgia,serif;\r\n\tline-height: 80%;\r\n\tcolor: #505080;\r\n}\r\n#pdyear {\r\n\tmargin: -1px 0;\r\n\tbackground: transparent;\r\n\tfont-size: 7pt;\r\n\tfont-weight: normal;\r\n\tletter-spacing: 0.2em;\r\n\tfont-family: Georgia,serif;\r\n\tcolor: #505080;\r\n}<\/code><\/pre>\n<p>I&#8217;ve shown only the important CSS elements for <i>posthead<\/i> and <i>postheader<\/i> that are required to make this work. &nbsp;Your theme may require more than what is shown.<\/p>\n<p>As you can see, the size and colors of the date stamp are created in the container <i>postdate<\/i>. &nbsp;With a width and height of 40px setting the border radius to half that value, in this case 20px, creates the circle. &nbsp;The 3 interior DIVs handle the style, size and position of the date elements to create the stamp effect. &nbsp;Of special not is the -1px margin for the <i>pdyear<\/i> DIV. &nbsp;This just nudges the year up 1 pixel to clear the stamp border without impinging on the day. <\/p>\n<p>Of course sizes and position and colors need to be adjusted to suit your theme. &nbsp;Hopefully this will make your WP theme a bit more fun should you try to play with this.<\/p>\n<p>I have a few more date styles to share in future posts. &nbsp;If you have a different fun shape or formatting please submit it for inclusion here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using CSS it&#8217;s easy to spice up your WordPress posts by adding some fun styling to the post date. &nbsp;I&#8217;m certain this translates well into other blog or CMS systems, but I&#8217;m just focusing on WordPress with this one.<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,16,30,41],"tags":[37,36,31],"class_list":["post-738","post","type-post","status-publish","format-standard","hentry","category-css","category-technology","category-web-development","category-wordpress","tag-css","tag-post-date","tag-wordpress"],"views":1883,"_links":{"self":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts\/738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=738"}],"version-history":[{"count":0,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=\/wp\/v2\/posts\/738\/revisions"}],"wp:attachment":[{"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.creed3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}